You are on page 1of 3

Setting up Pager Tag Files In Struts 1. Download pager-taglib-2.0.war into your webapps folder.

2. Restarting your tomcat server will cause the file to unpack and create a directory in your webapps titled "pager-taglib-2.0". To ensure that it was unpacked successfully, open http://localhost:8080/pager-taglib-2.0/ in your internet browser. 3. Copy pager-taglib.jar and pager-src.jar from the library folder of the pager-taglib-2.0 directory (pager-taglib-2.0/WEB-INF/lib) into a library folder in your context (ex. cstxxxx/WEB-INF/lib). 4. In Eclipse, you must recognize the jar files as referenced external jars. To do this, in Eclipse right click on your project and select Properties. Then, choose Java Build Path, then select the Libraries tab and click onAdd External Jars. Select the jar files in the library folder in your context. 5. Copy pager-taglib.tld into a jsp directory (create one if you have to) in your context (ex. cstxxxx/WEB-INF/jsp). The file can be found in the jsp folder of the pager-taglib-2.0 directory. 6. You must make a change to your web.xml for the pager-taglib.tld to be referenced. Do that by adding the following between and :

7. You will have to reload your context or restart your server after moving these files. Continue On To Creating Pager Tags (With Example)

I am using this taglib quite extensively and it works very well with Struts. Below is a fairly basic example jsp. Essentially, the pager url attribute specifies the destination when any of the navigation links is clicked. Request parameters required by the action class can be specified using the param tag. These can be literals (value="search") as in my example or use <bean:define> and specify the value attribute as the resulting variable (value="<%=expr%>"). The item tag defines each row to be displayed, and needs to be enclosed within <logic:iterate>. The index tag defines the navigation bar (prev, next etc) as a series of hyperlinks. The maxIndexPages attribute of the pager tag defines how many page numbers will be displayed in the navigation bar, i.e the below example will display [<<Prev] 1 2 3 4 5 6 7 8 9 10 [Next>>] assuming there are 10 pages worth of data. [<<Prev] and [Next>>] only display if there are previous or more pages. The maxPageItems attribute specifies how many detail rows per page to be displayed. I'm happy to answer any further questions or give examples. Cheers Malc <pg:pager url="AdvancedSearch.do" maxIndexPages="10" maxPageItems="15"> <pg:param name="action" value="search"/> <TABLE width="100%"> <TR> <TD align="center"> <TABLE width="60%" border="0"> <TR> <TH width="10%"><bean:message key="partnum.ecnsearchresults.ecnid"/></TH> <TH width="20%"><bean:message key="partnum.ecnsearchresults.model"/></TH> <TH width="10%"><bean:message key="partnum.ecnsearchresults.releasedate"/></TH> <TH width="10%"><bean:message key="partnum.ecnsearchresults.status"/></TH> </TR> <logic:iterate id="row" name="results" scope="request" type="com.sony.sde.sql.Row"> <pg:item> <TR> <TD><bean:write name="row" property="string[1]"/></TD> <TD><bean:write name="row" property="string[2]"/></TD> <TD><bean:write name="row" property="string[3]"/></TD> <TD><bean:write name="row" property="string[4]"/></TD> </TR> </pg:item> </logic:iterate> </TABLE> <TABLE width="60%" border="0"> <TR><TD>&nbsp;</TD></TR> <TR align="center"> <TD> <pg:index>

<pg:prev><a href="<%=pageUrl%>">[<< Prev]</a> </pg:prev> <pg:pages> <bean:define id="pageNo" value="<%=pagerPageNumber.toString()%>"/> <logic:equal name="pageNo" value="< %=pageNumber.toString()%>"> <%=pageNumber%> </logic:equal> <logic:notEqual name="pageNo" value="<%=pageNumber.toString()%>"> <a href="<%= pageUrl %>"><%= pageNumber %></a> </logic:notEqual> </pg:pages> <pg:next><a href="<%= pageUrl %>">[Next >>]</a> </pg:next> </pg:index> </TD> </TR> </TABLE> </TD> </TR> </TABLE> </pg:pager> -----Original Message----From: John Menke [mailto:[EMAIL PROTECTED]] Sent: 03 March 2002 02:08 To: struts-user Subject: paging taglib and struts? Does anyone any suggestions for implementing paging with struts? I have searched the archive and karl basel posted this: <snip> There's a good pager taglib at jsptags.com. I've used it in a struts app and does the job quite well when embedded in the iterate tags. <logic:iterate> <pg:item> Item Details </pg:item> </logic:iterate> <snip>

You might also like