Hi Team ,
I need to enclose the arraylist within square bracket and so used list.add("[") at the start and at the end as list.add("]") but it appends comma with the list .But need to get rid off the comma from the list and so could anyone please suggest on this .
Actual:[, [1245,480], [, [350,280], [300,250], ], ], [, [800,480], [, [300,250], [728,90], ], ]
Expected:[ [1245,480], [[350,280], [300,250]]], [[800,480], [[300,250], [728,90]]]
Solved! Go to Solution.
Views
Replies
Total Likes
I don't understand the complexity & usecase. However, you can certainly use the conditions at the start of the loop where you are building an array and at the last to not include the ",". In sling model, you have the control and you can easily use the core java features & add some logic to meet your desired need.
etc...
I don't understand the complexity & usecase. However, you can certainly use the conditions at the start of the loop where you are building an array and at the last to not include the ",". In sling model, you have the control and you can easily use the core java features & add some logic to meet your desired need.
etc...
Try to use toString() method on list which will automatically add braces at start and end of the list.
@Keerthi97 I would suggested to return the String/List whatever is the business requirement from the Sling Model once created and do the manipulation for appending the respective brackets i.e. opening "[" and closing "]" in your component's HTML.
<div data-sly-use.obj="com.mysite.core.models.MyClass"> [ ${obj.listString} ] </div>
Thanks
Why not storing your arrayList items in a map, and then iterate over the values of map in sightly .
I think that would be easy.
@Keerthi97 It will add. You are adding "[" as one item to list. What is your use and what are you trying to achieve. could you add some more details. That may be possible without adding "["
Views
Likes
Replies