Solved

iterating and displaying  ArrayList in <Logic:iterate>

Posted on 2004-10-17
4
5,811 Views
Last Modified: 2013-11-24
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
Comment
Question by:srivenky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 16

Expert Comment

by:suprapto45
ID: 12337218
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
 
LVL 29

Accepted Solution

by:
bloodredsun earned 200 total points
ID: 12865107
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question