aspose file tools*
The moose likes Struts and the fly likes Dynamic Attribute assignment (in Struts) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Dynamic Attribute assignment (in Struts)" Watch "Dynamic Attribute assignment (in Struts)" New topic
Author

Dynamic Attribute assignment (in Struts)

Aash Patel
Greenhorn

Joined: Sep 14, 2005
Posts: 24
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

Joined: Oct 14, 2005
Posts: 1
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


marcon
Aash Patel
Greenhorn

Joined: Sep 14, 2005
Posts: 24
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Dynamic Attribute assignment (in Struts)