Solved

iterating and displaying  ArrayList in <Logic:iterate>

Posted on 2004-10-17
4
5,793 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
4 Comments
 
LVL 16

Expert Comment

by:suprapto45
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Understanding @ResponseBody annotation 5 49
EvenOdd challenge 10 81
factorial example challenge 10 60
powerN  challenge 3 46
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now