Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5842
  • Last Modified:

iterating and displaying ArrayList in <Logic:iterate>

I need a solution for the following problem

<bean:define id="result1" name="resultsetform" property="rowResults"/>
<logic:iterate id="resultid1" name="result1">
<bean:write name="resultid1"/>
</logic:iterate>

I have stored the resultsetform in session
rowResults(gettermethod) is a bean which will return me ArrayList with values populated.

Please don't bother about ArrayList values getting populated.

I want to display the contents of the ArrayList in the following order,
value1,value2,value3,value4,value5
value6,value7,value8,value9,value10
.......
depending on the total size of the ArrayList

right now it displays as
value1
value2
value3
value4
value5
.....

The offset will be specified in the runtime. In the above scenario the offset is 5.
But in my program i will get the offset as a parameter.
I wanted to implement this in struts(no scriplets or for loop).

Please Help,
Thanks in advance.,

0
srivenky
Asked:
srivenky
1 Solution
 
suprapto45Commented:
Friends....

Have you ever used JSTL before? Something like <c:set../> or <c:out.../>. I am not sure whether it can be used or not but let me try...:)
0
 
bloodredsunCommented:
Very easy in JSTL. The JSTL tags have more or less replaced the logic tags for struts anyway. But you will have to use a type of for loop (but I think you were refering to using a jsp type for loop scriptlet).

<c:forEach var='rowResult' items='${sessionScope.resultsetform.rowResults}' begin='${param.start}' end='${param.cutoff}'>
      <c:out value='${rowResult}'/>
</c:forEach>


The above code retrieves a collection/map/list (here rowResults) from an object (resultsetform) in a scope (session). With the start and stop variables set by some request parameters called start and cutoff. The results of the expression are stored in the var variable fo use in the loop where you output it using c:out tags.

This means that:
http://www.myplace.com/myapp/mypage.do?start=1&cutoff=5
would give you the first 5 results in the rowset arraylist.

and

http://www.myplace.com/myapp/mypage.do?start=3&cutoff=8
would give you from 3 to 8

You will need to add the tld declaration:
<%@ taglib uri='http://java.sun.com/jstl/core' prefix='c' %>
in the page and also download the jstl jars.

No scriptlets, no fuss. Let me know if this helps.


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now