-
about struts logic:iterate tag (13 messages)
- Posted by: liu jonah
- Posted on: March 21 2004 21:17 EST
I want to write a collection to page.
I use table to present contents of collection.
But i want to write 4 elements of collection in one row.
How to use <logic:iterate> to implement it?
Any suggestion welcome!
thanks very much!Threaded Messages (13)
- <logic:iterate id="identification" name="collecitonobject".....> by Maruthi Ram on March 22 2004 06:48 EST
- <logic:iterate id="identification" name="collecitonobject".....> by liu jonah on March 22 2004 08:14 EST
-
<logic:iterate id="identification" name="collecitonobject".....> by Paul Strack on March 22 2004 10:29 EST
-
<logic:iterate id="identification" name="collecitonobject".....> by liu jonah on March 22 2004 09:44 EST
-
<logic:iterate id="identification" name="collecitonobject".....> by liu jonah on March 22 2004 10:35 EST
-
More than two rows by Paul Strack on March 23 2004 11:10 EST
-
More than two rows by liu jonah on March 23 2004 09:48 EST
- More than two rows by Paul Strack on March 23 2004 10:12 EST
-
More than two rows by liu jonah on March 23 2004 09:48 EST
-
More than two rows by Paul Strack on March 23 2004 11:10 EST
-
<logic:iterate id="identification" name="collecitonobject".....> by liu jonah on March 22 2004 10:35 EST
-
<logic:iterate id="identification" name="collecitonobject".....> by liu jonah on March 22 2004 09:44 EST
-
<logic:iterate id="identification" name="collecitonobject".....> by Paul Strack on March 22 2004 10:29 EST
- Fix the header. by deep iam on January 02 2009 04:15 EST
- by Neha Bhatia on March 30 2010 05:46 EDT
- about struts logic:iterate tag by ankit agarwal on June 11 2010 02:30 EDT
- <logic:iterate id="identification" name="collecitonobject".....> by liu jonah on March 22 2004 08:14 EST
- question by rahul pol on February 16 2011 01:42 EST
-
<logic:iterate id="identification" name="collecitonobject".....>[ Go to top ]
- Posted by: Maruthi Ram
- Posted on: March 22 2004 06:48 EST
- in response to liu jonah
Hi Jonah,
I think u have sufficient knowledge about work flow in Struts.
If u want to print a collection using <logic:iterate> first of alll u need to know the attributes that are used with this tag.
<logic:iterage> tag has jsp body and supports 9 attributes with it.
to make a looop for a collection it is sufficient to have attributes.
those are 1. id
2. name
1. id is the the identification what we are going to use to iterate the collection that is specified in the 'name' attribute.
2. name is the name of the collection that we want to iterate.
First of alll u need to set the collectiin object(name), which u want to iterete, in one of the scopes Viz. page, session, request, application.
And then u can accessa the collection object using its name in name attribute.
Eg.
ArrayList a;
.........//some code may be here.
HttpSession session=request.getSession();
session.setAttribute("maru",a);
........ //some code may be here.
in the jsp page u need to mention like this
<logic:iterage id="maruref" name"maru">
<TR>
<TD><bean:write name="maruref" property="property name "></TD>
.......
....
</TR>
</logic:iterate>
Here property name is the property name object 'a' for first enty
when the loop iterates again it prients the propertis of next entriens(next object in a) of 'a'
<bean:write name..../> tag us used to write the approprite property of the collectio object in the page
reply me still any doubt....
I will try....
best of luck.
Regards,
MaRu. -
<logic:iterate id="identification" name="collecitonobject".....>[ Go to top ]
- Posted by: liu jonah
- Posted on: March 22 2004 08:14 EST
- in response to Maruthi Ram
First of all,thanks you reply.
You didn't uderstand my question.Maybe I didn't represented myself correctly.
For example:I have a collection that has 8 elements.I want to represent them like follow.
element1 element2 element3 element4
element5 element6 element7 element8
In here element(i) indicate the properties of element I want to represent.
In other words,I want to represent more than one element of collection in only one row of table.
Following what you said,I could only represent one element of collection in one row of table.
I wish I could represent myself correctly this time.
Thanks a lot. -
<logic:iterate id="identification" name="collecitonobject".....>[ Go to top ]
- Posted by: Paul Strack
- Posted on: March 22 2004 10:29 EST
- in response to liu jonah
Use the iterate tags "indexId" attribute to store the index count in a page context variable. Whenever the index is evenly divisibly by 4, insert a new table-row tag.
<logic:iterate id="identification" name="collecitonobject" indexId="counter"> -
<logic:iterate id="identification" name="collecitonobject".....>[ Go to top ]
- Posted by: liu jonah
- Posted on: March 22 2004 21:44 EST
- in response to Paul Strack
Thank you very much!!!
I got it. -
<logic:iterate id="identification" name="collecitonobject".....>[ Go to top ]
- Posted by: liu jonah
- Posted on: March 22 2004 22:35 EST
- in response to liu jonah
If I want to write more than two rows,how to do?
Each row represent more than one elements. -
More than two rows[ Go to top ]
- Posted by: Paul Strack
- Posted on: March 23 2004 11:10 EST
- in response to liu jonah
I am not sure what you mean. Do you mean this?
element1 element2 element3 element4
element5 element6 element7 element8
element9 element10 element11 element12
...
If so, insert a <tr> tag every time the counter is evenly divible by 4 (counter % 4 == 0). -
More than two rows[ Go to top ]
- Posted by: liu jonah
- Posted on: March 23 2004 21:48 EST
- in response to Paul Strack
Yes,it is exactly my means.
Coulud give me a simple example about how to write such tag using
<logic:iterate/> -
More than two rows[ Go to top ]
- Posted by: Paul Strack
- Posted on: March 23 2004 22:12 EST
- in response to liu jonah
Unfortunately, the logic tags of Struts are limited, and can't handle this kind of computation. To do something like this, you would need some kind of expression language. For example, JSTL supports this kind of thing nicely, and would be a better option if your server supports servlet 2.3+.
Of course, you can always fall back to scripting, which works no matter what:
<table>
<logic:iterate id="identification" name="collectionobject" indexId="counter">
<%
Integer counter = (Integer) pageContext.getAttribute("counter");
/* Begin row if divisible by 1 */
if (counter.intValue() % 4 == 1) { %>
<tr>
<% } %>
<td>[print element]</td>
</logic:iterate>
</table>
Technically, this is not 100% correct, because I am not generating the closing </tr> tag, but the browser should render things correctly anyway, and I don't feel like grinding out all the logic. -
Fix the header.[ Go to top ]
- Posted by: deep iam
- Posted on: January 02 2009 04:15 EST
- in response to Maruthi Ram
Hi Maru.Your post here is helpful to everyone no doubt.Thanks. I regularly use logic:iterate in my application.But,the problem is the Header of the table is not being fixed that I require very much. Waiting for your tips. With Regards.... ~Deep. -
[ Go to top ]
- Posted by: Neha Bhatia
- Posted on: March 30 2010 05:46 EDT
- in response to Maruthi Ram
Hi,
I have set a arraylisi in a property of bean, den i want to show these values with checkboxes in a row. how can i do this? -
about struts logic:iterate tag[ Go to top ]
- Posted by: ankit agarwal
- Posted on: June 11 2010 02:30 EDT
- in response to Neha Bhatia
Hi, I had used struts logic iterate tag and arraylist to display items in a dropdown list. Here is code: <html:select property="name" >
<logic:iterate id="emp" name="emplist">
<html:option value="${emp}">${emp}</html:option>
</logic:iterate></html:select>. I hope that helps you. If you had doubts regarding this code, kindly let me know.
-
query[ Go to top ]
- Posted by: rahul pol
- Posted on: February 16 2011 01:44 EST
- in response to ankit agarwal
How can i apply condition on number of iterations of<logic:iterator> tag without using scriplet.
-
question[ Go to top ]
- Posted by: rahul pol
- Posted on: February 16 2011 01:42 EST
- in response to liu jonah
How can i apply condition on number of iterations of <logic:iterator> tag