Discussions

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!

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.

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 element4element5 element6 element7 element8In 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.

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:

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.

TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations technology projects - with its network of technology-specific websites, events and online magazines.