转:Pager Tag Library v2.0

Overview

The Pager Tag Library is the easy and flexible way to implement paging of large data sets in JavaServer Pages (JSP). It can emulate all currently known paging styles with minimal effort. It also includes re-usable index styles that emulate the search result navigators of popular web sites such as GoogleSM, AltaVista® and Yahoo!. The Pager Tag Library does most of the work for you by dynamically organizing your data set into pages and generating a browsable index with virtually any look desired.

 


License

 

/*
 *  Pager Tag Library
 *
 *  Copyright (C) 2002  James Klicman <james@jsptags.com>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

The full license can be found in the file LICENSE included with this distribution or on the web at http://www.gnu.org/copyleft/lesser.txt.

 


Requirements

 

  • JavaServer Pages 1.1 compliant Web Server/Servlet Engine
  • Java 1.1 or later runtime environment

 


Installation

 

The Pager Tag Library is distributed as a ready-to-run Web Application Archive (WAR). You can deploy the distribution WAR file as-is to your JavaServer Pages 1.1 compliant server. The WAR file may also be used as the basis for a new web application. Follow the instructions bellow to integrate the Pager Tag Library into an existing web application.

The files referenced in the instructions are located in the distribution WAR file.

 

    WEB-INF/lib/
	pager-taglib.jar

    WEB-INF/jsp/
	pager-taglib.tld
	alltheweb.jsp
	altavista.jsp
	google.jsp
	jsptags.jsp
	lycos.jsp
	simple.jsp
	texticon.jsp
	yahoo.jsp

    images/
        jsptags.gif

 

Tomcat 3.x/4.x Instructions
  1. Choose the context in which to install. I'll use the "/examples" context created in the default Tomcat configuration for the following instructions.

  2. Edit the tomcat/webapps/examples/WEB-INF/web.xml file and add the following lines inside the body of the <web-app>...</web-app> tags.

    <taglib>
      <taglib-uri>
        http://jsptags.com/tags/navigation/pager
      </taglib-uri>
      <taglib-location>
        /WEB-INF/jsp/pager-taglib.tld
      </taglib-location>
    </taglib>
    
  3. Copy the file pager-taglib.tld to the tomcat/webapps/examples/WEB-INF/jsp directory.

  4. Copy pager-taglib.jar to the tomcat/webapps/examples/WEB-INF/lib directory. You may need to create a tomcat/webapps/examples/WEB-INF/lib directory if it does not already exist.

    Please Note: The 3.1 Beta version of Tomcat does not support tag libraries in jar files. The following steps will install for Tomcat 3.1 Beta.

    1. Copy pager-taglib.jar to the tomcat/webapps/examples/WEB-INF/classes directory.

    2. Change current working directory to the tomcat/webapps/examples/WEB-INF/classes directory.

    3. Extract the contents of the pager-taglib.jar file with the command:
          jar xvf pager-taglib.jar

    4. There will be a META-INF directory created during the extraction, this can be removed.

    5. The pager-taglib.jar file can now be removed from the tomcat/webapps/examples/WEB-INF/classes directory.

  5. Copy the files pager-demo.jsp and jsptags.gif to the tomcat/webapps/examples directory.

  6. Copy the file the re-usable index style files alltheweb.jsp, altavista.jsp, google.jsp, jsptags.jsp, lycos.jsp, simple.jsp, texticon.jsp and yahoo.jsp to the tomcat/webapps/examples/WEB-INF/jsp directory.

  7. Shutdown and restart tomcat.

  8. Check out http://<yourserver>/examples/pager-demo.jsp

JRun 3.0 Instructions
  1. Choose the server and web-app in which to install. The following instructions will install in JRun's default server and default web-app which is jrun/servers/default/default-app.

  2. Edit the jrun/servers/default/default-app/WEB-INF/web.xml file and add the following lines inside the body of the <web-app>...</web-app> tags.

    <taglib>
      <taglib-uri>
        http://jsptags.com/tags/navigation/pager
      </taglib-uri>
      <taglib-location>
        /WEB-INF/jsp/pager-taglib.tld
      </taglib-location>
    </taglib>
    
  3. Copy the file pager-taglib.tld to the jrun/servers/default/default-app/WEB-INF/jsp directory.

  4. Copy pager-taglib.jar to the jrun/servers/default/default-app/WEB-INF/lib directory.

  5. Copy the files pager-demo.jsp and jsptags.gif to the jrun/servers/default/default-app directory.

  6. Copy the re-usable index style files alltheweb.jsp, altavista.jsp, google.jsp, jsptags.jsp, lycos.jsp, simple.jsp, texticon.jsp and yahoo.jsp to the jrun/servers/default/default-app/WEB-INF/jsp directory.

  7. Restart JRun Default Server.

  8. Check out http://<yourserver>/pager-demo.jsp

Generic Instructions
  1. Choose the web-app in which to install. I'll use web-app/ to represent a generic web-app directory.

  2. Edit the web-app/WEB-INF/web.xml file and add the following lines inside the body of the <web-app>...</web-app> tags.

    <taglib>
  <taglib-uri>
    http://jsptags.com/tags/navigation/pager
  </taglib-uri>
  <taglib-location>
    /WEB-INF/jsp/pager-taglib.tld
  </taglib-location>
</taglib>
 
  1. Copy the file pager-taglib.tld to the web-app/WEB-INF/jsp directory.

  2. Copy pager-taglib.jar to the web-app/WEB-INF/lib directory.

  3. Copy the files pager-demo.jsp and jsptags.gif to the web-app/ directory.

  4. Copy the re-usable index styles alltheweb.jsp, altavista.jsp, google.jsp, jsptags.jsp, lycos.jsp, simple.jsp, texticon.jsp and yahoo.jsp to the web-app/WEB-INF/jsp directory.

  5. Restart your Servlet/JSP engine.

  6. Check out http://<yourserver>/pager-demo.jsp

 


Examples

Please note that since the ex:searchresults tag is fictitious, the following examples will not run as is. You must provide your own looping data source. As an alternative, you may repeat as many <pg:item>...</pg:item> tags as you wish to generate a static list of items.

Example 1. A Simple Pager

[ (1) |< Previous ] [ (1) << Previous ]  1   2   3   4   5   6   7   8   9   10  [ Next >> (3) ] [ Last >| (21) ]

<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg" %>

<pg:pager>
  <pg:param name="keywords"/>

  <ex:searchresults>
    <pg:item>
      <%= searchResult %>
    </pg:item>
  </ex:searchresults>
  <pg:index>

    <pg:first>
      <a href="<%= pageUrl %>">[ (<%= pageNumber %>) |&lt; Previous ]</a>
    </pg:first>

    <pg:prev>
      <a href="<%= pageUrl %>">[ (<%= pageNumber %>) &lt;&lt; Previous ]</a>
    </pg:prev>

    <pg:pages>
       <a href="<%= pageUrl %>"><%= pageNumber %></a> 
    </pg:pages>

    <pg:next>
      <a href="<%= pageUrl %>">[ Next &gt;&gt; (<%= pageNumber %>) ]</a>
    </pg:next>

    <pg:last>
      <a href="<%= pageUrl %>">[ Last &gt;| (<%= pageNumber %>) ]</a>
    </pg:last>

  </pg:index>
</pg:pager>
 

 

 

Example 2. An AltaVista® Pager

Result Pages:  [<< Prev]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20  [Next >>]

<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg" %>

<pg:pager url="http://www.altavista.com/cgi-bin/query" maxIndexPages="20"
             export="currentPageNumber=pageNumber">
  <pg:param name="pg"/>
  <pg:param name="q"/>

  <ex:searchresults>
    <pg:item>
      <%= searchResult %>
    </pg:item>
  </ex:searchresults>

  <pg:index>
    <font face=Helvetica size=-1>Result Pages:
    <pg:prev>&nbsp;<a href="<%= pageUrl %>">[&lt;&lt; Prev]</a></pg:prev>
    <pg:pages><%
      if (pageNumber.intValue() < 10) { 
        %>&nbsp;<%
      }
      if (pageNumber == currentPageNumber) { 
        %><b><%= pageNumber %></b><%
      } else { 
        %><a href="<%= pageUrl %>"><%= pageNumber %></a><%
      }
    %>
    </pg:pages>
    <pg:next>&nbsp;<a href="<%= pageUrl %>">[Next &gt;&gt;]</a></pg:next>
    <br></font>
  </pg:index>
</pg:pager>
 

 

 

Example 3. A GoogleSM Pager

This index references Google.com for images. If you're not currently connected to the Internet you will see broken images.

 

Result Page: 
Previous

1

2

3

4

5

6

7

8

9

10

11

Next

 

<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg" %>

<pg:pager url="http://www.google.com/search" index="half-full"
             export="currentPageNumber=pageNumber">
  <pg:param name="q"/>
  <pg:param name="sa" value="N"/>

  <ex:searchresults>
    <pg:item>
      <%= searchResult %>
    </pg:item>
  </ex:searchresults>

  <pg:index>
    <center>
    <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 Page: </font></td>
    <pg:prev 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 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>
    </center>
  </pg:index>
</pg:pager>
 

 

 


Tag Reference

 


pg:pager

The pg:pager tag defines the pager. Inside the pg:pager tag, use the pg:param tag to add request parameters, use the pg:item tag to define items of information, use the pg:index tag to define a navigation index, and use the pg:first, pg:prev, pg:page, pg:pages, pg:next, pg:skip and pg:last tags to define navigation elements.

Syntax
<pg:pager
  id="value"
  url="url"
  index="center|forward|half-full"
  items="int"
  isOffset="true|false"
  maxItems="int"
  maxPageItems="int"
  maxIndexPages="int"
  export="expression"
  scope="page|request"
>
...
</pg:pager>
  
Export Variables
Full NameShort Name(s)TypeScope
pageOffsetoffsetIntegerNested
pageNumberpage, numberIntegerNested

 

id

Specifies the id of the tag. The default id is "pager". The id is used as a prefix for the pager.offset request parameter. If id is specified as "pg1" the request parameter becomes pg1.offset. See also the scope attribute.

url

Specifies the url to be used in the generated index. The default is the url of the current JSP page as returned by <%= request.getRequestURI() %> with any request parameters removed.

index

Specifies the behavior of the index. The valid values for this attribute are "center", "forward" and "half-full". The default index behavior is "center".

When the "center" behavior is specified, the size of the index is fixed to maxIndexPages or the total number of pages (whichever is lower) and the current page number is placed as close to the center of the index as possible.

When the "forward" behavior is specified, the size of the index is fixed to maxIndexPages or the number of remaining pages (whichever is lower) and the next page is the first page of the index.

When the "half-full" behavior is specified, the size of the index starts out at half of maxIndexPages or the total number of pages (whichever is lower) and grows to maxIndexPages as pages are browsed. The "half-full" behavior emulates GoogleSM.

items

Specifies the number of items available in the data set. This is useful when the data set size is known and can be retrieved in page sized chunks. When this attribute is set, the index can be displayed before and after the items.

isOffset

Specifies that the first pg:item will be offset to the current pager offset. This is useful when the data source is a database that supports the limit & offset clauses. The default value is false.

maxItems

Specifies the maximum number of items to be available in the generated index. The default and maximum value is 2147483647.

maxPageItems

Specifies the maximum number of items to be displayed in each page. The default value is 10.

maxIndexPages

Specifies the maximum number of pages to be included in the generated index. The default value is 10.

export

Specifies the variables to export. See also the export variables section.

scope

Specifies the scope of exported variables. The valid values for this attribute are "page" and "request". The default is "page". If scope is "request" the pg:index and navigation tags can be included from another JSP page.

 


pg:param

The pg:param tag is used inside the pg:pager tag to add request parameters to each page url in the index.

Syntax
<pg:param
  id="value"
  name="value"
  value="value"
 />

 

id

When the scope for pg:pager is "request" and the pg:pager id attribute is set, this specifies the id for the pg:pager tag. The value of id must match the value specified for the pg:pager tag.

name

Specifies the required request parameter name.

value

Specifies an optional static value. The default is the request parameter specified by the name attribute.


pg:item

The pg:item tag is used inside the pg:pager tag to define page items. If the item is out of range for the current page it is not displayed.

Syntax
<pg:item
  id="value"
>
...
</pg:item>

 

id

When the scope for pg:pager is "request" and the pg:pager id attribute is set, this specifies the id for the pg:pager tag. The value of id must match the value specified for the pg:pager tag.


pg:index

The pg:index tag is used inside the pg:pager tag to specify the index. If all of the items fit on one page the index is not displayed.

Syntax
<pg:index
  id="value"
  export="expression"
>
...
</pg:index>
  
Export Variables
Full NameShort NameTypeScope
itemCountitemsIntegerNested
pageCountpagesIntegerNested

 

id

When the scope for pg:pager is "request" and the pg:pager id attribute is set, this specifies the id for the pg:pager tag. The value of id must match the value specified for the pg:pager tag.

export

Specifies the variables to export. See also the export variables section.


pg:first

The pg:first tag is used inside the pg:index or pg:pager tag to create a link to the first page.

Syntax
<pg:first
  id="value"
  unless="current|indexed"
  export="expression"
>
<%= pageUrl %>
<%= pageNumber %>
...
</pg:first>
  
Export Variables
Full NameShort Name(s)TypeScope
pageUrlurlStringNested
pageNumberpage, numberIntegerNested
firstItemfirstIntegerNested
lastItemlastIntegerNested

 

id

When the scope for pg:pager is "request" and the pg:pager id attribute is set, this specifies the id for the pg:pager tag. The value of id must match the value specified for the pg:pager tag.

unless

Specifies when the first page link should not be displayed. If "current" is specified, the link will not be displayed if the first page is the current page. If "indexed" is specified, the link will not be displayed if the first page is displayed in the index. The default is to always display the link.

export

Specifies the variables to export. The default is to export pageUrl and pageNumber. The firstItem and lastItem variables are the first and last item numbers on the the page. See also the export variables section.

 


pg:prev

The pg:prev tag is used inside the pg:index or pg:pager tag to create a link to the previous page. If there is no previous page the exported variables will be null.

Syntax
<pg:prev
  id="value"
  ifnull="true|false"
  export="expression"
>
<%= pageUrl %>
<%= pageNumber %>
...
</pg:prev>
  
Export Variables
Full NameShort Name(s)TypeScope
pageUrlurlStringNested
pageNumberpage, numberIntegerNested
firstItemfirstIntegerNested
lastItemlastIntegerNested

 

id

When the scope for pg:pager is "request" and the pg:pager id attribute is set, this specifies the id for the pg:pager tag. The value of id must match the value specified for the pg:pager tag.

ifnull

Specifies whether or not to evaluate the body if there is no previous page to the current page. The default is false, do not evaluate body. If the value is true then the body is evaluated when there is no previous page and the exported variables are set to null.

export

Specifies the variables to export. The default is to export pageUrl and pageNumber. The firstItem and lastItem variables are the first and last item numbers on the page. See also the export variables section.

 


pg:page

The pg:page tag is used inside the pg:index or pg:pager tag to create a link to the current page or export information about the current page.

Syntax
<pg:page
  id="value"
  export="expression"
>
<%= pageUrl %>
<%= pageNumber %>
...
</pg:prev>
  
Export Variables
Full NameShort Name(s)TypeScope
pageUrlurlStringNested
pageNumberpage, numberIntegerNested
firstItemfirstIntegerNested
lastItemlastIntegerNested

 

id

When the scope for pg:pager is "request" and the pg:pager id attribute is set, this specifies the id for the pg:pager tag. The value of id must match the value specified for the pg:pager tag.

export

Specifies the variables to export. The default is to export pageUrl and pageNumber. The firstItem and lastItem variables are the first and last item numbers on the page. See also the export variables section.

 


pg:pages

The pg:pages tag is used inside the pg:index or pg:pager tag to create a link to each page in the index. The body of the pg:pages tag is processed for each page in the index. The export variable pageNumber can be compared with page number exported from pg:pager to determine the current page.

Syntax
<pg:pages
  id="value"
  export="expression"
>
<%= pageUrl %>
<%= pageNumber %>
...
</pg:pages>
  
Export Variables
Full NameShort Name(s)TypeScope
pageUrlurlStringNested
pageNumberpage, numberIntegerNested
firstItemfirstIntegerNested
lastItemlastIntegerNested

 

id

When the scope for pg:pager is "request" and the pg:pager id attribute is set, this specifies the id for the pg:pager tag. The value of id must match the value specified for the pg:pager tag.

export

Specifies the variables to export. The default is to export pageUrl and pageNumber. The firstItem and lastItem variables are the first and last item numbers on this page. See also the export variables section.


pg:next

The pg:next tag is used inside the pg:index or pg:pager tag to create a link to the next page. If there is no next page the exported variables will be null.

Syntax
<pg:next
  id="value"
  ifnull="true|false"
  export="expression"
>
<%= pageUrl %>
<%= pageNumber %>
...
</pg:next>
  
Export Variables
Full NameShort Name(s)TypeScope
pageUrlurlStringNested
pageNumberpage, numberIntegerNested
firstItemfirstIntegerNested
lastItemlastIntegerNested

 

id

When the scope for pg:pager is "request" and the pg:pager id attribute is set, this specifies the id for the pg:pager tag. The value of id must match the value specified for the pg:pager tag.

ifnull

Specifies whether or not to evaluate the body if there is no next page to the current page. The default is false, do not evaluate body. If the value is true then the body is evaluated when there is no next page and the exported variables are set to null.

export

Specifies the variables to export. The default is to export pageUrl and pageNumber. The firstItem and lastItem variables are the first and last item numbers on this page. See also the export variables section.

 


pg:last

The pg:last tag is used inside the pg:index or pg:pager tag to create a link to the last page.

Syntax
<pg:last
  id="value"
  unless="current|indexed"
  export="expression"
>
<%= pageUrl %>
<%= pageNumber %>
...
</pg:last>
  
Export Variables
Full NameShort Name(s)TypeScope
pageUrlurlStringNested
pageNumberpage, numberIntegerNested
firstItemfirstIntegerNested
lastItemlastIntegerNested

 

id

When the scope for pg:pager is "request" and the pg:pager id attribute is set, this specifies the id for the pg:pager tag. The value of id must match the value specified for the pg:pager tag.

unless

Specifies when the last page link should not be displayed. If "current" is specified, the link will not be displayed if the last page is the current page. If "indexed" is specified, the link will not be displayed if the last page is displayed in the index. The default is to always display the link.

export

Specifies the variables to export. The default is to export pageUrl and pageNumber. The firstItem and lastItem variables are the first and last item numbers on this page. See also the export variables section.

 


pg:skip

The pg:skip tag is used inside the pg:index or pg:pager tag to create a link to the page number calculated by adding the value of the pages attribute to the current page number. If the target skip page does not exist the exported variables will be null.

The pg:prev and pg:next tags operate relative to the current offset and are preferred to pg:skip for single page increments. If the current offset is not a multiple of maxPageItems due to a dynamic change in the maxPageItems value, the pg:next and pg:prev tags ensure that no items are skipped.

Syntax
<pg:skip
  id="value"
  ifnull="true|false"
  pages="int"
  export="expression"
>
<%= pageUrl %>
<%= pageNumber %>
...
</pg:skip>
  
Export Variables
Full NameShort Name(s)TypeScope
pageUrlurlStringNested
pageNumberpage, numberIntegerNested
firstItemfirstIntegerNested
lastItemlastIntegerNested

 

id

When the scope for pg:pager is "request" and the pg:pager id attribute is set, this specifies the id for the pg:pager tag. The value of id must match the value specified for the pg:pager tag.

ifnull

Specifies whether or not to evaluate the body if the calculated skip page does not exist. The default is false, do not evaluate body. If the value is true and the skip page does not exist, the body is evaluated and the exported variables are set to null.

pages

Specifies the number of pages to skip relative to the current page. Negative numbers can be used to skip backwards.

export

Specifies the variables to export. The default is to export pageUrl and pageNumber. The firstItem and lastItem variables are the first and last item numbers on this page. See also the export variables section.

 


export variables

The export attribute is a flexible way access the tag variables that are available. A special feature of the export attribute is the ability to control the name of exported variables.

The pg:pager tag has two export variables, pageOffset and pageNumber. The export expression used to export the pageOffset variable would simply be export="pageOffset". This would cause the pageOffset variable to be available as <%= pageOffset %>. Both pg:pager variables can be exported with export="pageOffset,pageNumber". Each variable name may be separated by either a comma ",", semicolon ";", or spaces " ". A final semicolon may optionally appear at the end of the expression.

The following export expressions are equivilent.

export="pageOffset,pageNumber"
export="pageOffset;pageNumber"
export="pageOffset pageNumber"
export="pageOffset,pageNumber;"
export="pageOffset;pageNumber;"
export="pageOffset, pageNumber;"

All of the variables have one or more short names which can be specified. The short name of pageOffset is offset. The short names for pageNumber are page and number. If the short name is specified, the variable is declared using the short name. The export expression export="offset" would cause the pageOffset variable to be available as <%= offset %>.

The export attribute also enables the specification of custom variable names. This may be used to avoid variable name conflicts or to specify variable names in your preferred language. The export expression export="versatz=offset" would cause the pageOffset variable to be available as <%= versatz %>. The long or short variable name can be used in the expression, for example export="seiteVersatz=pageOffset" is also valid.

Examples of valid expressions.

export="pageOffset;"
export="offset, pageNumber"
export="versatz=offset, zahl = number;"

Examples of invalid expressions.

export="pageOffset,"
export="pageOffset pageNumber"
export="pageOffset, pageNumber,"
export="nonexistentVariable"
export="offset=foo"
(should be foo=offset)


Upgrading to v2.0

 

Export Variables

The default export behavior of the pg:pager tag has been changed. It no longer exports pagerOffset, pagerPageNumber and pagerMaxItems by default.

To emulate the previous behavior, add the pg:pager attribute:

export="pagerOffset=pageOffset,pagerPageNumber=pageNumber"

The export of pagerMaxItems has been dropped in this release due the value originating outside of the Pager Tag Library. If you need access the value of maxItems simply re-use the input value given to the pg:pager tag.

Recompiling JSP Files

JSP files compiled with an older release of the Pager Tag Library may need to be recompiled. Recompiling may be necessary even when no modifications are required to the JSP file. The simplest way to cause a recompile is by touching the JSP file to update it's timestamp. Updating the timestamp can be done by editing and saving the JSP file.

 


Troubleshooting

 

Translation Time Errors

If you get translation time errors reported for your JSP file, it may be a problem with your JavaServer Pages implementation.

Many JSP implementations do not correctly handle conversions of attributes in custom actions. This means that instead of automatically converting an attribute such as maxPageItems="5" to the correct (in this case) native type of int, the JSP engine incorrectly attempts to pass the attribute as a String.

The correct behavior has been clarified by JSP 1.1a Errata Issue #7 which states:

...
Conversions in attributes in custom actions

 

What type of conversions are applied to attribute values of a custom action. Specifically, what is done to a request-time attribute value, and what is done to a literal string.

Resolution

A request-time attribute value is passed with no conversion.

A literal string is converted following the rules in Table 2-4, section 2.13.2.
...

If you encounter this issue, I would recommend reporting the bug to your JSP server vendor.

In the mean time, you can work around the issue by using request-time values for any attributes that expect an int or boolean value. To specify a request time attribute simply wrap the value in <%= %>. Attributes such as maxPageItems="5" would become maxPageItems="<%= 5 %>" and ifnull="true" would become ifnull="<%= true %>".

 


Release History

 

  • December 20th, 2002 v2.0 Feature Release

    • New pg:pager attributes: index, items, export and scope.

    • New tags: pg:page, pg:first, pg:last and pg:skip.

    • New export variables: itemCount, pageCount, firstItem and lastItem.

    • New flexible export variable declaration syntax.

    • Support for external index style pages.

    • Eight included re-usable index styles.

    • Support for indexes before items.

    • Support for multi-value request parameters.

    • Numerous performance optimizations including reduced object creation, improved class hierarchy and thorough finalization of methods and classes.

    • Compatibility with JavaServer Pages version 1.2 tag caching.

    • Changed default exports of pg:pager tag and removed export variable pagerMaxItems.

    • Web Application Archive (WAR) distribution format.

  • September 26th, 2000 v1.1 Maintenance Release

    • Fixed bug which caused a ClassCastException by calling javax.servlet.jsp.tagext.TagData.getAttributeString() on a request-time attribute.

    • Modified pager-demo.jsp to use request-time attributes which are more compatible with the current releases of commercial JSP servers. (see JSP 1.1a Errata Issue #7)

    • Updated installation instructions for Tomcat.

    • Added installation instructions for JRun 3.0.

    • Added generic installation instructions.

  • March 29th, 2000 v1.0 Initial Release 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值