| Author |
logic:iterate
|
manasa teja
Ranch Hand
Joined: May 27, 2002
Posts: 325
|
|
is it possible to iterate thru a Arraylist using logic:iterate. I put this arraylist in request object and want to access this in JSP.. is it possible.. if so, pleae let me know hoe to achive it??
|
MT
|
 |
Bernardus Irmanto
Greenhorn
Joined: Oct 03, 2003
Posts: 23
|
|
yes it is possible. I posted a reply to a similar question ( yashnoo iyo, subject : put arraylist in the session? ). pls go the topic rgds beN
|
 |
manasa teja
Ranch Hand
Joined: May 27, 2002
Posts: 325
|
|
and I have a service class, where actually, we shld fetch some data from database and put it in a Array list.. Right now, we hardcoded this... teh code for this serveice class and in the Execute method of the action class.. Now, I have to access this request object and diaply in a JSP using logic:iterate.. please help me out on this.. [ October 08, 2003: Message edited by: M K Raman ] [ October 08, 2003: Message edited by: M K Raman ]
|
 |
Bernardus Irmanto
Greenhorn
Joined: Oct 03, 2003
Posts: 23
|
|
Hi, among the logic:iterate tags, there are 3 attributes which are needed to specify the collection to be iterated in the jsp page. They are : 1. Collection : which is a runtime expression that evaluates to a collection 2. name : which is the name of the jsp bean containing the collection to be iterated over 3. property : the name of the property of the jsp bean specified by name( point 2) In all those 3 attributes, you need to have a jsp bean which has a collection member variable to be iterated over. So, In your case, you cant put the arraylist directly to the request object. you can define a jsp bean, declaring one arraylist, fill the arraylist with the arraylist returned by your getDepartments method. The next step is put the jsp bean in the request object. then in the jsp you can have logic:iterate tag which will look like : <logic:iterate name="depatrmentBean" property="departments" id="row" indexId="index" scope="request" > where the departmentBean is your jsp bean(refered by the name attribute). In the the departmentBean you need to have an ArrayList named departments(refered by property attributed). and then you can use html:text/bean:write to output each member variables. <html:text property='<%= "department["+index+"].deptId" %>' > you might be a bit confused. We have "departments" (see the name attribute)and department(see the property attribute of html:text tag). They represent two different things. departments is the collection you want to iterate over, and the department, is the object contained in the arraylist. hope this can help
|
 |
manasa teja
Ranch Hand
Joined: May 27, 2002
Posts: 325
|
|
Thanks beN I tried implemetning your logic... But, its not working for me.. Ineed to look into this again... I need to look into Form code again!! [ October 08, 2003: Message edited by: M K Raman ]
|
 |
Anselm Paulinus
Ranch Hand
Joined: Sep 05, 2003
Posts: 389
|
|
M K Raman; I am not quite sure what you are trying to print; but I assume it to be the descriptions on the bean; you might give this a try and let me know if it works. <logic:iterate property="departments" id="row" scope="request" > <bean:write name="row" property = "description"/> </logic:iterate> On the other hand if your intention was to print id as well as description then you might have to use this <logic:iterate property="departments" id="row" scope="request" > <bean:write name="row" property = "id"/> <bean:write name="row" property = "description"/> </logic:iterate> Also; I am not sure why you have a non default constructor in your bean when you have setters that do the same thing for you.
|
 |
Bernardus Irmanto
Greenhorn
Joined: Oct 03, 2003
Posts: 23
|
|
hi Anselm, I dont think the code will work. the property attribute of the logic:iterate tag "must" have the jsp bean which is refered by the name attribute, associated with it. rgds beN
|
 |
Anselm Paulinus
Ranch Hand
Joined: Sep 05, 2003
Posts: 389
|
|
You are right Irmanto; Raman; please change the code to use name in place of property as shown below <logic:iterate name="departments" id="row" scope="request" > <bean:write name="row" property = "description"/> </logic:iterate>
|
 |
manasa teja
Ranch Hand
Joined: May 27, 2002
Posts: 325
|
|
beN, Anselm.. With the help of beN's reply, yesterday, I was able to solve it and display it .. Thanks beN for looking into this...
|
 |
 |
|
|
subject: logic:iterate
|
|
|