[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

dividing page into multiple pages (struts)

Posted on 2006-05-10
47
Medium Priority
?
808 Views
Last Modified: 2010-05-18

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
Comment
Question by:laptopcomputer
  • 29
  • 18
47 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 16647478
Have you seen the pager taglib?

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

Author Comment

by:laptopcomputer
ID: 16648611

Thanks
I have actually, i'll give it a try, where do I put the taglib war file in my tomcat?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 16648693
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:laptopcomputer
ID: 16648884

Once I drop the war in WAR in tomcat/webapps, should'nt it automatically expand?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 16648897
yup...

Assuming tomcat's running...
0
 

Author Comment

by:laptopcomputer
ID: 16648982

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

Author Comment

by:laptopcomputer
ID: 16649518

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

Expert Comment

by:TimYates
ID: 16655880
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
 

Author Comment

by:laptopcomputer
ID: 16655906

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

Expert Comment

by:TimYates
ID: 16655988
Yup :-)  Should do :-)

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

Tim
0
 

Author Comment

by:laptopcomputer
ID: 16656009

thats great thanks, do you think that this will work with struts?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 16656049
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
 

Author Comment

by:laptopcomputer
ID: 16656136

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
 

Author Comment

by:laptopcomputer
ID: 16656264

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

Expert Comment

by:TimYates
ID: 16656302
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
 

Author Comment

by:laptopcomputer
ID: 16656413

Very sorry Tim, i posted the wrong page, struts is still relatively new to me...
0
 
LVL 35

Expert Comment

by:TimYates
ID: 16656452
hehehe, no worries ;-)
0
 

Author Comment

by:laptopcomputer
ID: 16656501
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
 
LVL 35

Accepted Solution

by:
TimYates earned 1050 total points
ID: 16656528
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
 

Author Comment

by:laptopcomputer
ID: 16656785

Cheers, where is pager-index.jsp? do I have to create it myself?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 16656841
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
 

Author Comment

by:laptopcomputer
ID: 16657010

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

Any ideas?
0
 

Author Comment

by:laptopcomputer
ID: 16658148

I have fixed that error but its still not working ;-(
0
 
LVL 35

Expert Comment

by:TimYates
ID: 16658179
what's it doing/saying?
0
 

Author Comment

by:laptopcomputer
ID: 16658292

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

?


0
 

Author Comment

by:laptopcomputer
ID: 16658319

my servlet.jar is out of date?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 16658467
You're using Tomcat 3.1

Everything is out of date ;-)

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

Author Comment

by:laptopcomputer
ID: 16658472

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
 

Author Comment

by:laptopcomputer
ID: 16658667

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

Expert Comment

by:TimYates
ID: 16658707
>> 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
 

Author Comment

by:laptopcomputer
ID: 16658794

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

Expert Comment

by:TimYates
ID: 16658856
no
0
 

Author Comment

by:laptopcomputer
ID: 16659019

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

Author Comment

by:laptopcomputer
ID: 16659264

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

Author Comment

by:laptopcomputer
ID: 16666377

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

Author Comment

by:laptopcomputer
ID: 16666380

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

Expert Comment

by:TimYates
ID: 16666391
what do you have in that jsp?  (pager-index)?

Tim
0
 

Author Comment

by:laptopcomputer
ID: 16666884
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
 

Author Comment

by:laptopcomputer
ID: 16667149

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

Expert Comment

by:TimYates
ID: 16667157
Does the demo WAR that comes with the pager work?
0
 

Author Comment

by:laptopcomputer
ID: 16667249


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

Expert Comment

by:TimYates
ID: 16667265
If the demo, which should work doesn't work, then you know you're wasting your time
0
 
LVL 35

Expert Comment

by:TimYates
ID: 16667278
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
 

Author Comment

by:laptopcomputer
ID: 16667311

Tried it there Tim and yes it does work.
0
 

Author Comment

by:laptopcomputer
ID: 16668019

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
 

Author Comment

by:laptopcomputer
ID: 16668864

are you  still posting on this Tim?
0
 

Author Comment

by:laptopcomputer
ID: 16673419

Thanks for the help
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Currently, there is an issue with being able to copy values from an external application to a dropdown list in Project Web Access (PWA).  The standard copy and paste methods don't seem to work properly. Here is a way to accomplish this task to s…
If anyone asked you to network diagram of the internet, it was drawn in the form of a fluffy cloud which further became known as cloud computing. Popularly cloud computing is defined as workloads that run over the internet in a commercial provider’s…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Screencast - Getting to Know the Pipeline
Suggested Courses

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question