user1726508
user1726508

Reputation: 73

how to iterate a ArrayList from session into JSP using Struts 2 OGNL tags

I have a class where I am creating a non empty ArrayList and putting it is not a session. Now, I want to iterate that list which kept in session into my JSP page.

I tried it but nothing is coming.

in action class

..................
books = new ArrayList<Bookdetails>();
session.put(BillTransactionBooksConstants.BOK, books);
return SUCCUSS;

Note : I tested my list is not empty and it is correctly adding into session. My only problem is how can I show this list into my JSP from session.

BillTransactionBooksConstants:

package v.esoft.actions.booktransaction; 
public class BillTransactionBooksConstants 
{
    public static final String BOK = "BOK"; 
}

shortbill.jsp:

<s:iterator value="#session.BillTransactionBooksConstants.BOK" status="userStatus">
    <s:property value="Bookdetails.bookTitile" />
    <br/>
</s:iterator>

Upvotes: 1

Views: 6346

Answers (2)

Dave Newton
Dave Newton

Reputation: 160311

Refer only to the property name, and use the constant value directly:

<s:iterator value="#session.BOK">
    <s:property value="bookTitle" />
    <br/>
</s:iterator>

Note that I've corrected the spelling of the property.

Also note that "SUCCESS" is spelled "SUCCESS", not "SUCCUSS".

If you wish to use the constant name you should be able to use the following, but I didn't test it:

<s:iterator value="#session[@v.esoft.actions.booktransaction.BillTransactionBooksConstants@BOK]">

Assuming static member access is enabled.

Upvotes: 4

Roman C
Roman C

Reputation: 1

Try this

<s:iterator value="#session.BOK" status="userStatus">
<tr class="<s:if test="%{#userStatus.odd == true} ">odd</s:if> <s:else>even</s:else>">
<td><s:property value="bookTitile" /></td>

Upvotes: 0

Related Questions