Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamic Attribute assignment (in Struts)

 
Aash Patel
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using the DisplayTag library to display my data in table/grid form. DisplayTag has a convenient paging feature which can be enabled as below:

In my JSP
<display:table name="sessionScope.results" export="true" defaultorder="descending" pagesize="20">
<display:column property="prop1" title="Location" sortable="true" headerClass="sortable"/>
<display:column property="prop2" title="Description" sortable="true" headerClass="sortable"/>

<display:setProperty name="export.xml" value="false" />
<display:setProperty name="export.csv" value="false" />
</display:table>

The "pagesize" attribute enables paging with each page having 20 records.

What I want to be able to do is set that number to 0 (no paging) or 20 (paging) dynamically. In my ActionForm and Action class, I have created a setdisplay attribute which the user sets in the beginning of the application. I then make that property available in the session scope. Once I have it in the session scope, in my jsp page how can I use it to assign the value for my pagesize.

Seems pretty simple - I just cant get it?
 
Mark Siegman
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's actually pretty easy. Since you have either the default page size of 0 or the user preferred page size in your session object just build your display tag as:

<% String pageSize = session.getAttribute("PAGESIZE"); %>
<display:table pagesize="<%=pageSize%>">

-Mark
 
Aash Patel
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had initially tried that Mark. It dint work. I later realized that the pagesize attribute accepts an integer rather than a string. So all I had to do was get the string from the session, convert it to an int and then assign the int value dynamically.

Thanks for your reply though.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic