Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add values in arraylist using JSTL

 
M Sharma
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have defined array list object in my jsp page as

<jsp:useBean id="varietyIdList" class="java.util.ArrayList" scope="page"/>

i will get values in a particular loop one by one and in that loop i want to add those values in the arraylist defined above, using JSTL ??.

We are not supposed to use scriptlets in jsp.
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably want to check out the JSTL documentation for "c:forEach" -- sound like that's what you're looking for.
 
M Sharma
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am aware that if we provide an collection to for:Each, we can get the elements of that collection one by one. But my problem is setting an arraylist in that for loop

In other words i am looking for the replacement of the following code using JSTL

If i wud have used scriptlet i wud have written

arrayListObj.add(value);

...(but i am not allowed to use scriptlets )

so what will i write to acheive the same in JSTL ??
[ October 20, 2004: Message edited by: Manish Sachdev ]
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the addition (or modification) of objects does not really support by JSTL, as it aims to make presentation logic easier in JSP, not to update the values.

Nick
 
M Sharma
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had already have set the hashmap with the help JSTL...and the syntax was...

<c:set target="${groupByMap}" property="fromWineTypeId" value="${wineTypeException.fromWineTypeDto.id}" />

where "groupByMap" was the object reference declared using the useBean tag and key of the hashmap was "fromWineTypeId" and the value to that key was assigned with the help of value attribute.


i tried with the following syntax for ArrayList but it didn't worked out...

<c:set target="${myArrayListRef}" property="*" value="${myValue}" />
<c:set target="${myArrayListRef}" value="${myValue}" />



is there no other way i can acheive it thru JSTL ??
[ October 20, 2004: Message edited by: Manish Sachdev ]
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code works as it is just an assignment of variables.

But what you now wanna is to modify the content of the variables, which I really dont think that JSTL should support that.

Nick
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic