aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes How to add values in arraylist using JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "How to add values in arraylist using JSTL" Watch "How to add values in arraylist using JSTL" New topic
Author

How to add values in arraylist using JSTL

M Sharma
Ranch Hand

Joined: Dec 13, 2001
Posts: 106
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.


Regards, Manish
SCJP 1.4
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
You probably want to check out the JSTL documentation for "c:forEach" -- sound like that's what you're looking for.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
M Sharma
Ranch Hand

Joined: Dec 13, 2001
Posts: 106
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

Joined: Nov 07, 2003
Posts: 4982
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


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
M Sharma
Ranch Hand

Joined: Dec 13, 2001
Posts: 106
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

Joined: Nov 07, 2003
Posts: 4982
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
 
subject: How to add values in arraylist using JSTL