• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 819
  • Last Modified:

dividing page into multiple pages (struts)


Hi all, im trying to divide a table in a jsp page (based on the struts architecture) into multiple pages.

This is the approach I was thinking of:
To divide up the pages into rows of ten, length parameter would be set to 10 (length="10") and offset set to 0 (offset = "0") for the first page,
for the second page : length="10" , offset = "10",
for the third page : length="10" , offset = "20" etc.

An object to be created which contains the offset and length of each page.
When the user loads the first page the offset and length are read and applied to the page.
If the user clicks "next" the length is read and added to the offset.
If the user clicks "previous" the length is read and subracted from the offset.
The page is then refreshed.

Any comments/help would be greatly appreciated.

Thanks
0
laptopcomputer
Asked:
laptopcomputer
  • 29
  • 18
1 Solution
 
TimYatesCommented:
Have you seen the pager taglib?

http://jsptags.com/tags/navigation/pager/index.jsp
0
 
laptopcomputerAuthor Commented:

Thanks
I have actually, i'll give it a try, where do I put the taglib war file in my tomcat?
0
 
TimYatesCommented:
To run their examples, just drop the WAR in tomcat/webapps

To add it to your application, there is extensive documentation on their site:

http://jsptags.com/tags/navigation/pager/pager-taglib-2.0.html#installation
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
laptopcomputerAuthor Commented:

Once I drop the war in WAR in tomcat/webapps, should'nt it automatically expand?
0
 
TimYatesCommented:
yup...

Assuming tomcat's running...
0
 
laptopcomputerAuthor Commented:

hmmm, i dont seem to have a webapps folder, im using tomcat3.3. any ideas?
Thanks again
0
 
laptopcomputerAuthor Commented:

ive expanded the war manually, i might just leave this open until i get my tomcat configured, your sure that taglib can be used with struts?
0
 
TimYatesCommented:
Oooooof...  Can I ask why you are using Tomcat 3.3?

I don't think this will work with 3.3, as it is so old...

Can you upgrade to 5.X?  (5.5 if you have Java 5, 5.0 if you have java 1.4)

Tim
0
 
laptopcomputerAuthor Commented:

I have to use Tomcat3.3, i cant really go into the reasons why.

It gives installation instructions for tomcat3.x here:http://jsptags.com/tags/navigation/pager/pager-taglib-2.0.html#installation
(the link you posted earlier)

So it should work?
0
 
TimYatesCommented:
Yup :-)  Should do :-)

(sorry, I didn't see that it supported 3.x) :-)

Tim
0
 
laptopcomputerAuthor Commented:

thats great thanks, do you think that this will work with struts?
0
 
TimYatesCommented:
I use it in my struts application :-)

Basically, you generate your data table exactly as you do now, but put a some pager tags at the top and bottom of your table, and a <pg:item tag round each row of your data

Then it gives you the paging ability :-)

The taglib comes with a few examples of how to get your paging to look like well known sites (google, etc)

It's pretty cool :-)

Tim
0
 
laptopcomputerAuthor Commented:

Thats brill Tim thanks, i might just leave this question open until I get it working if you dont mind. I will increase the points.
0
 
laptopcomputerAuthor Commented:

Below is the struts page Im trying to add the paging too but im clueless as too how to add the paging tags?

<table border="0" cellspacing="1" cellpadding="4" width="323">
    <tr>
      <td colspan="2" width="648" height="42" class="myheading">
        <bean:message key="****" />
      </td>
    </tr>
  <html:form action="getProc">
    <tr>
      <td class="outputbox" width="324">
        <bean:message key="****" />
      </td>
      <td class="outputbox" width="324">
        <bean:message key="****" />
      </td>
    </tr>
    <tr>
      <td class="outputbox" width="324">
        <html:select property="****" onchange="submit()" >
          <html:**** name="new" property="****" value="val" label="new" />
        </html:select>
      </td>
      <td class="outputbox" width="324">
        <logic:notEmpty name="****" property="newProp">
          <html:select property="newProp">
            <html:option property="old" value="val" label="new" />
          </html:select>
        </logic:notEmpty>
        <logic:empty name="select" property="subProcessesList">
          <bean:message key="sel.noSubProcess" />
        </logic:empty>
      </td>
    </tr>
    <tr>
      <td colspan="5" class="newClass"><img src="/newimage.gif" width="1" height="5"></td>
    </tr>
    <tr>
      <td colspan="5" height="5">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2" height="35" align="center">
        <html:image src="image1.gif" property="****" /> &nbsp;<html:image src="/image3.gif" property="buttons.newButton" /> &nbsp;<html:image src="image5.gif" property="****" />
      </td>
    </tr>
    <tr>
      <td colspan="2" height="35">&nbsp;</td>
    </tr>
  </html:form>
</table>

Thanks
0
 
TimYatesCommented:
I can't see where in that page you have a lot of data that would need paging...

Isn't that just a simple form?
0
 
laptopcomputerAuthor Commented:

Very sorry Tim, i posted the wrong page, struts is still relatively new to me...
0
 
TimYatesCommented:
hehehe, no worries ;-)
0
 
laptopcomputerAuthor Commented:
Apologies again, here is the correct file:

<div align="center">
  <table border="0" cellspacing="1" cellpadding="0" width="648">
    <tr>
      <td colspan="5" width="648" height="42" class="****">
        <bean:message key="****" />
      </td>
    </tr>
    <html:form action="****">
      <tr>
        <td class="****">
          <bean:message key="****" />
        </td>
        <td class="outputbox" colspan="4">
          <bean:message key="****" />
        </td>
      </tr>

      <logic:iterate id="****" name="****" property="****" indexId="ctr">
        <tr>
      <logic:notEqual name="****" property="****" value="****">
        <td class="****">
          <bean:write name="****" property="****" />
        </td>
        <td class="outputbox">
          <bean:write name="****" property="****" filter="****" />
        </td>
      </logic:notEqual>

      <logic:equal name="****" property="****" value="****">
        <td class="outputbox">
          <bean:write name="****" property="****" />
          <br>
          <logic:notEmpty name="****" property="****">
            <html:select name="businessRule" property="label" indexed="true" onchange="submit()">
              <html:optionsCollection name="****" property="****" value="label" label="label"/>
            </html:select>
          </logic:notEmpty>
        </td>
        <td class="outputbox">
          <bean:write name="****" property="****" />
        </td>
      </logic:equal>
      <td class="out" align="center">
        <html:image src="/images/buttons/edit.gif"
                    property="buttons.edit" indexed="true" />
      </td>
      <td class="outputbox" align="center">

      </logic:iterate>
      <tr>
        <td colspan="5" class=""><img src="image4.gif" width="10" height="55"></td>
      </tr>
      <tr>
        <td colspan="5" height="15">&nbsp;</td>
      </tr>
    <tr>
      <td colspan="5" align="center">

      </td>
    </tr>
      <tr>
        <td colspan="4" height="35">&nbsp;</td>
      </tr>
    </html:form>
  </table>
</div>
0
 
TimYatesCommented:
Right, it's going to be SOMETHING like this:

have a look at the examples that came with the pager tag lib as well, to see how it fits together, and where the jars need to go, etc:


<div align="center">
  <table border="0" cellspacing="1" cellpadding="0" width="648">
    <tr>
      <td colspan="5" width="648" height="42" class="****">
        <bean:message key="****" />
      </td>
    </tr>
    <html:form action="****">
      <tr>
        <td class="****">
          <bean:message key="****" />
        </td>
        <td class="outputbox" colspan="4">
          <bean:message key="****" />
        </td>
      </tr>
    <pg:pager index="half-full"
              maxPageItems="25"
              maxIndexPages="10"
              export="currentPageNumber=pageNumber"
              url=""
              scope="request">
      <pg:param name="style"/>
      <pg:param name="position"/>
      <pg:param name="index"/>
      <pg:param name="maxPageItems"/>
      <pg:param name="maxIndexPages"/>

      <logic:iterate id="****" name="****" property="****" indexId="ctr">
      <pg:item>
        <tr>
      <logic:notEqual name="****" property="****" value="****">
        <td class="****">
          <bean:write name="****" property="****" />
        </td>
        <td class="outputbox">
          <bean:write name="****" property="****" filter="****" />
        </td>
      </logic:notEqual>

      <logic:equal name="****" property="****" value="****">
        <td class="outputbox">
          <bean:write name="****" property="****" />
          <br>
          <logic:notEmpty name="****" property="****">
            <html:select name="businessRule" property="label" indexed="true" onchange="submit()">
              <html:optionsCollection name="****" property="****" value="label" label="label"/>
            </html:select>
          </logic:notEmpty>
        </td>
        <td class="outputbox">
          <bean:write name="****" property="****" />
        </td>
      </logic:equal>
      <td class="out" align="center">
        <html:image src="/images/buttons/edit.gif"
                    property="buttons.edit" indexed="true" />
      </td>
      <td class="outputbox" align="center">

       </pg:item>
      </logic:iterate>
      <tr>
        <td colspan="5" class=""><img src="image4.gif" width="10" height="55"></td>
      </tr>
      <tr>
        <td colspan="5" height="15">&nbsp;</td>
      </tr>
    <tr>
      <td colspan="5" align="center">

      </td>
    </tr>
      <pg:index>
        <jsp:include page="/scripts/pager-index.jsp" flush="true"/>
      </pg:index>
    </pg:pager>
      <tr>
        <td colspan="4" height="35">&nbsp;</td>
      </tr>
    </html:form>
  </table>
</div>
0
 
laptopcomputerAuthor Commented:

Cheers, where is pager-index.jsp? do I have to create it myself?
0
 
TimYatesCommented:
that's the index thing...  (ie so it looks like Google)

in the WAR you downloaded, it's:

/WEB-INF/jsp/google.jsp

for example :-)  (mine is just called "pager-index.jsp" and is in a scripts folder)

Hope this makes sense...

Tim
0
 
laptopcomputerAuthor Commented:

That makes sense alright, ive got that working now but im getting this error:
"bean currentPageNumber  not found within scope "

Any ideas?
0
 
laptopcomputerAuthor Commented:

I have fixed that error but its still not working ;-(
0
 
TimYatesCommented:
what's it doing/saying?
0
 
laptopcomputerAuthor Commented:

Im getting:
java.lang.NoClassDefFoundError: javax/servlet/jsp/tagext/TagSupport

?


0
 
laptopcomputerAuthor Commented:

my servlet.jar is out of date?
0
 
TimYatesCommented:
You're using Tomcat 3.1

Everything is out of date ;-)

Have a look in servlet.jar...  is that class there?
0
 
laptopcomputerAuthor Commented:

im thinking it maybe something to do with :
taglib uri="http://jsptags.com/tags/navigation/pager"

Which is in google.jsp (the page im trying to use)
0
 
laptopcomputerAuthor Commented:

The class is there, I added servlet.jar to my jre/lib/ext folder. Its not throwing that error anymore but its throwing this one again:
bean currentPageNumber  not found within scope
0
 
TimYatesCommented:
>> I added servlet.jar to my jre/lib/ext folder.

NOOOOOOooooooooooooooooooooooooooooo!

it should already be in the Tomcat/lib folder...  Try doing it inline like they show you in all the examples

Does the demo WAR work?

Tim
0
 
laptopcomputerAuthor Commented:

So im assuming i should not have pager-taglib.jar into jre/lib/ext?
0
 
TimYatesCommented:
no
0
 
laptopcomputerAuthor Commented:

ah right, i think ill just ry and implement it my own way, ive followed the intructions but it just wont work
0
 
laptopcomputerAuthor Commented:

Should'nt "currentPageNumber" be the name of a class in the taglibs jar file?
0
 
laptopcomputerAuthor Commented:

Ive finally fixed it, i was missing <%@ taglib uri="myuri" prefix="pg" %> at the top of the jsp I posted.
Very annoying
0
 
laptopcomputerAuthor Commented:

But <jsp:include page="/scripts/pager-index.jsp" flush="true"/> does not work.

The page does'nt get called and no error is thrown?
0
 
TimYatesCommented:
what do you have in that jsp?  (pager-index)?

Tim
0
 
laptopcomputerAuthor Commented:
no, its just exactly whats in google.jsp (from tag library)

<%@ page session="false" %>
<%@ taglib uri="pages" prefix="pg" %>
<jsp:useBean id="currentPageNumber" type="java.lang.Integer" scope="request"/>
<i>This index references <font
color="#0000cc">G</font><font color="#cccc00">oo</font><font
color="#0000cc">g</font><font

color="#00cc00">l</font><font
color="#cc0000">e</font>.com for images.<br>
If you're not currently connected to the Internet you will see broken

images.</i><br>
&nbsp;<br>
<table border=0 cellpadding=0 width=10% cellspacing=0>
<tr align=center valign=top>
<td valign=bottom><font

face=arial,sans-serif
  size=-1>Result&nbsp;Page:&nbsp;</font></td>
<pg:prev export="pageUrl" ifnull="<%= true %>">
  <% if (pageUrl != null) { %>
   

<td align=right><A HREF="<%= pageUrl %>"><IMG
      SRC=http://www.google.com/nav_previous.gif alt="" border=0><br>
    <b>Previous</b></A></td>
  <%

} else { %>
    <td><IMG SRC=http://www.google.com/nav_first.gif alt="" border=0></td>
  <% } %>
</pg:prev>
<pg:pages>
  <% if (pageNumber ==

currentPageNumber) { %>
    <td><IMG SRC=http://www.google.com/nav_current.gif alt=""><br>
    <font color=#A90A08><%= pageNumber %></font></td>
  <%

} else { %>
    <td><A HREF="<%= pageUrl %>"><IMG
      SRC=http://www.google.com/nav_page.gif alt="" border=0><br>
    <%= pageNumber %></A></td>
 

<% } %>
</pg:pages>
<pg:next export="pageUrl" ifnull="<%= true %>">
  <% if (pageUrl != null) { %>
    <td><A HREF="<%= pageUrl %>"><IMG
     

SRC=http://www.google.com/nav_next.gif alt="" border=0><br>
    <b>Next</b></A></td>
  <% } else { %>
    <td><IMG

SRC=http://www.google.com/nav_last.gif alt="" border=0></td>
  <% } %>
</pg:next>
</tr>
</table>
0
 
laptopcomputerAuthor Commented:

When I remove <pg:index> </pg:index> tags the file gets invoked. But its not working.

Yesturday Tim you said "Right, it's going to be SOMETHING like this:" am I missing something?

Many thanks
0
 
TimYatesCommented:
Does the demo WAR that comes with the pager work?
0
 
laptopcomputerAuthor Commented:


I dont think there is much point spending time trying to get the demo working because its more or less the same as getting it too work with my web app.

Also its not as simple as just putting the war file in the webapps folder because it does'nt expand automatically so i did'nt take it any further from there.

The file you posted of my struts jsp file should appear, thats correct?
0
 
TimYatesCommented:
If the demo, which should work doesn't work, then you know you're wasting your time
0
 
TimYatesCommented:
Just expand the WAR using winzip or similar (file-roller on linux)

put it in a folder like:

tomcat/webapps/pagertest

restart tomcat and go to

http://localhost:8080/pagertest

Tim
0
 
laptopcomputerAuthor Commented:

Tried it there Tim and yes it does work.
0
 
laptopcomputerAuthor Commented:

it works!!!!!! but not perfectly, when segmenting the pages it adds a "?offset=x" to the url and then loads that url. The problem is instead of re loading the page it just re-directs to a home page
0
 
laptopcomputerAuthor Commented:

are you  still posting on this Tim?
0
 
laptopcomputerAuthor Commented:

Thanks for the help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 29
  • 18
Tackle projects and never again get stuck behind a technical roadblock.
Join Now