简体   繁体   中英

how to iterate a arraylist from session into jsp using struts2 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>

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM