Link to home
Start Free TrialLog in
Avatar of laptopcomputer
laptopcomputer

asked on

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
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Have you seen the pager taglib?

http://jsptags.com/tags/navigation/pager/index.jsp
Avatar of laptopcomputer
laptopcomputer

ASKER


Thanks
I have actually, i'll give it a try, where do I put the taglib war file in my tomcat?
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

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

Assuming tomcat's running...

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

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?
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

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?
Yup :-)  Should do :-)

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

Tim

thats great thanks, do you think that this will work with struts?
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

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.

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
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?

Very sorry Tim, i posted the wrong page, struts is still relatively new to me...
hehehe, no worries ;-)
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>
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Cheers, where is pager-index.jsp? do I have to create it myself?
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

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

Any ideas?

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

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

?



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

Everything is out of date ;-)

Have a look in servlet.jar...  is that class there?

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)

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
>> 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

So im assuming i should not have pager-taglib.jar into jre/lib/ext?

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

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

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

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

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

Tim
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>

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
Does the demo WAR that comes with the pager work?


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?
If the demo, which should work doesn't work, then you know you're wasting your time
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

Tried it there Tim and yes it does work.

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

are you  still posting on this Tim?

Thanks for the help