You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Oleg V Alexeev <go...@penza.net> on 2001/06/15 23:11:15 UTC

PROPOSAL - tag

Hello struts-dev,

  I create <logic:pager> tag handler to simplify page by page data
  displaying.

  Here is short description and sample of use.

<taglib>
    <tlibversion>1.0</tlibversion>
    <jspversion>1.1</jspversion>
    <shortname>logic</shortname>
    <uri>http://jakarta.apache.org/struts/tags-logic-1.0</uri>
    <tag>
        <name>pager</name>
        <tagclass>org.apache.struts.taglib.logic.PagerTag</tagclass>
        <bodycontent>JSP</bodycontent>
 <!-- Name to be used in page to refer to this Pager-->
        <attribute>
            <name>id</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
 <!-- Name to store Pager tag body in page scope variable - call Pager
      once, save result and display it in page at any point. -->
        <attribute>
            <name>resultId</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
 <!-- Type of labels - page numbers or row ranges. -->
        <attribute>
            <name>labelType</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
 <!-- Class to use as backend Pager support -->
        <attribute>
            <name>type</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
 <!-- Show or not pager in place. Useful to generate pager and show it
      multiple times. -->
        <attribute>
            <name>show</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
 <!-- Name of the page scope variable (Integer) with offset of the
      first row.-->
        <attribute>
            <name>offset</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
 <!-- Length of the page. -->
        <attribute>
            <name>pageSize</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
 <!-- Total length of the list. -->
        <attribute>
            <name>totalSize</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
 <!-- Name for the paramater name (in URL) to be used as page size.
      -->
        <attribute>
            <name>pageSizeName</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
 <!-- Name for the paramater name (in URL) to be used as offset.
      -->        
        <attribute>
            <name>offsetName</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
    </tag>
</taglib>

Sample of JSP page with pager tag -

<bean:define id="offset" name="newsSlide" property="offset"
               type="java.lang.Integer"/>
<bean:define id="pageSize" name="newsSlide" property="slideLength"
               type="java.lang.Integer"/>
<bean:define id="totalSize" name="newsSlide" property="totalLength"
               type="java.lang.Integer"/>

<logicext:pager id="pager" resultId="pagerPanel"
   show="false" offset="offset" pageSize="pageSize"
   totalSize="totalSize">
 <logic:greaterThan name="pager" property="pagesTotal" value="1">
  <table>
   <tr>
    <td>
     <logic:equal value="true" property="hasPrev" name="pager">
      <html:link property="prev.link" name="pager" forward="news">Prev</html:link>
     </logic:equal>
     <logic:equal value="false" property="hasPrev" name="pager">Prev</logic:equal>
    </td>
     <logic:iterate property="linksIterator" name="pager" id="pagerItem">
      <td>
       <logic:equal value="false" property="isCurrent" name="pagerItem">
        <html:link property="link" name="pagerItem" forward="news">
         <bean:write property="label" name="pagerItem"/>
        </html:link>
       </logic:equal>
       <logic:equal value="true" property="isCurrent" name="pagerItem">
        <bean:write property="label" name="pagerItem"/>
       </logic:equal>
      </td>
     </logic:iterate>
    <td>
     <logic:equal value="true" property="hasNext" name="pager">
      <html:link property="next.link" name="pager" forward="news">Next</html:link>
     </logic:equal>
     <logic:equal value="false" property="hasNext" name="pager">Next</logic:equal>
    </td>
   </tr>
  </table>
 </logic:greaterThan>
</logicext:pager>

<bean:write name="pagerPanel" filter="false"/>

.... page of the list

<bean:write name="pagerPanel" filter="false"/>

-- 
Best regards,
 Oleg                          mailto:gonza@penza.net



Re[2]: PROPOSAL - tag

Posted by Oleg V Alexeev <go...@penza.net>.
Hello Martin,

Thursday, June 28, 2001, 6:08:40 AM, you wrote:

MC> Oleg,

MC> (Yes, I know this is an old post, I'm replying to - work is getting in the
MC> way these days. ;-) )

MC> I guess I need some help in understanding how this works. Could you give a
MC> brief description of the ideas behind the tag?

Action or ActionServlet itself (with help of bean-factory)
  1. creates instance of ArrayList (filled with data beans from
     database) or CachedRowSet (populated from result set) - it uses
     'offset' and 'pageSize' request parameters of form attributes to
     retrieve rows from result set from 'offset' and length of 'pageSize'.
  2. wrap it with Slide class object (contains fields 'offset',
    'pageSize' and 'totalSize' to use it with Pager class)
  3. store Slide in request or in session scope

At jsp page three bean:define tags are used to define 'offset',
'pageSize' and 'totalSize' as page scope variables (Integer) under
appropriate names.

<bean:define id="offset" name="newsSlide" property="offset"
               type="java.lang.Integer"/>
<bean:define id="pageSize" name="newsSlide" property="slideLength"
               type="java.lang.Integer"/>
<bean:define id="totalSize" name="newsSlide" property="totalLength"
               type="java.lang.Integer"/>

(May be this is dummy overhead, of course... But I pass one object
 only to the target scope - my idea was that it is more reliable. May
 be it is wrong - your words force me to doubt about it.)
  
PagerTag in jsp-page uses this variables ('offset' and blah, blah,
blah...) to create, instantiate and register Pager in page scope
inside of PagerTag body.

 <logicext:pager id="pager" resultId="pagerPanel"
    show="false" offset="offset" pageSize="pageSize"
    totalSize="totalSize">
    
 </logicext:pager>

Inside of pager tag body we can refer to the pager object by name from
'id' attribute and use standart struts tags - bean:write and
logic:iterate to display info from pager tag.

For example, Pager contains property 'linksIterator' to access
iterator via links to the pages -

      <logic:iterate property="linksIterator" name="pager" id="pagerItem">
       <td>
       <logic:equal value="false" property="isCurrent" name="pagerItem">
         <html:link property="link" name="pagerItem" forward="news">
          <bean:write property="label" name="pagerItem"/>
         </html:link>
        </logic:equal>
        <logic:equal value="true" property="isCurrent" name="pagerItem">
         <bean:write property="label" name="pagerItem"/>
        </logic:equal>
       </td>
      </logic:iterate>

Each link is PagerEntry class object and contains two properties -
'label' (String) and 'link' (Map to generate parameters to call some
page). And more - we can use 'properties' attribute in PagerTag to
specify page scope bean (Map) with parameters to pass it to each link,
generated by Pager.

Result of PagerTag processing can be hidden by setting attribute
'show' to false and we can specify attribute 'resultId' to store this
result in page scope as String and show it multiple times later.

-- 
Best regards,
 Oleg                            mailto:gonza@penza.net



Re: PROPOSAL - tag

Posted by Martin Cooper <ma...@tumbleweed.com>.
Oleg,

(Yes, I know this is an old post, I'm replying to - work is getting in the
way these days. ;-) )

I guess I need some help in understanding how this works. Could you give a
brief description of the ideas behind the tag? What objects are being
created where, and being used how? What would my action have to do, and what
would my JSP page look like, if I needed to be able to page through a
(possibly huge) list from a database?

It seems to me, from some of the attribute names you have defined, that it
might be simpler to define a class which represents the "chunk" of data you
are currently presenting relative to the total being paged through. This
class would then handle things like the count for this chunk, the total
size, etc. An instance of this class would be stored by the action, either
in a form bean or in the request or session, and referenced from the pager
tag and navigation tags. Doing this would avoid having to use the
<bean:define> tag to obtain the data from the form and pass it to the other
tags.

We have done something along these lines. It's not perfect, but it's fairly
straighforward to use in the JSP. Having the class representing the chunk
means that navigation tags can access it via the pager tag itself, and the
JSP page doesn't have to know.

--
Martin Cooper


----- Original Message -----
From: "Oleg V Alexeev" <go...@penza.net>
To: <st...@jakarta.apache.org>
Sent: Friday, June 15, 2001 2:11 PM
Subject: PROPOSAL - <logic:pager> tag


> Hello struts-dev,
>
>   I create <logic:pager> tag handler to simplify page by page data
>   displaying.
>
>   Here is short description and sample of use.
>
> <taglib>
>     <tlibversion>1.0</tlibversion>
>     <jspversion>1.1</jspversion>
>     <shortname>logic</shortname>
>     <uri>http://jakarta.apache.org/struts/tags-logic-1.0</uri>
>     <tag>
>         <name>pager</name>
>         <tagclass>org.apache.struts.taglib.logic.PagerTag</tagclass>
>         <bodycontent>JSP</bodycontent>
>  <!-- Name to be used in page to refer to this Pager-->
>         <attribute>
>             <name>id</name>
>             <required>true</required>
>             <rtexprvalue>true</rtexprvalue>
>         </attribute>
>  <!-- Name to store Pager tag body in page scope variable - call Pager
>       once, save result and display it in page at any point. -->
>         <attribute>
>             <name>resultId</name>
>             <required>false</required>
>             <rtexprvalue>true</rtexprvalue>
>         </attribute>
>  <!-- Type of labels - page numbers or row ranges. -->
>         <attribute>
>             <name>labelType</name>
>             <required>false</required>
>             <rtexprvalue>true</rtexprvalue>
>         </attribute>
>  <!-- Class to use as backend Pager support -->
>         <attribute>
>             <name>type</name>
>             <required>false</required>
>             <rtexprvalue>true</rtexprvalue>
>         </attribute>
>  <!-- Show or not pager in place. Useful to generate pager and show it
>       multiple times. -->
>         <attribute>
>             <name>show</name>
>             <required>false</required>
>             <rtexprvalue>true</rtexprvalue>
>         </attribute>
>  <!-- Name of the page scope variable (Integer) with offset of the
>       first row.-->
>         <attribute>
>             <name>offset</name>
>             <required>true</required>
>             <rtexprvalue>true</rtexprvalue>
>         </attribute>
>  <!-- Length of the page. -->
>         <attribute>
>             <name>pageSize</name>
>             <required>true</required>
>             <rtexprvalue>true</rtexprvalue>
>         </attribute>
>  <!-- Total length of the list. -->
>         <attribute>
>             <name>totalSize</name>
>             <required>true</required>
>             <rtexprvalue>true</rtexprvalue>
>         </attribute>
>  <!-- Name for the paramater name (in URL) to be used as page size.
>       -->
>         <attribute>
>             <name>pageSizeName</name>
>             <required>false</required>
>             <rtexprvalue>true</rtexprvalue>
>         </attribute>
>  <!-- Name for the paramater name (in URL) to be used as offset.
>       -->
>         <attribute>
>             <name>offsetName</name>
>             <required>false</required>
>             <rtexprvalue>true</rtexprvalue>
>         </attribute>
>     </tag>
> </taglib>
>
> Sample of JSP page with pager tag -
>
> <bean:define id="offset" name="newsSlide" property="offset"
>                type="java.lang.Integer"/>
> <bean:define id="pageSize" name="newsSlide" property="slideLength"
>                type="java.lang.Integer"/>
> <bean:define id="totalSize" name="newsSlide" property="totalLength"
>                type="java.lang.Integer"/>
>
> <logicext:pager id="pager" resultId="pagerPanel"
>    show="false" offset="offset" pageSize="pageSize"
>    totalSize="totalSize">
>  <logic:greaterThan name="pager" property="pagesTotal" value="1">
>   <table>
>    <tr>
>     <td>
>      <logic:equal value="true" property="hasPrev" name="pager">
>       <html:link property="prev.link" name="pager"
forward="news">Prev</html:link>
>      </logic:equal>
>      <logic:equal value="false" property="hasPrev"
name="pager">Prev</logic:equal>
>     </td>
>      <logic:iterate property="linksIterator" name="pager" id="pagerItem">
>       <td>
>        <logic:equal value="false" property="isCurrent" name="pagerItem">
>         <html:link property="link" name="pagerItem" forward="news">
>          <bean:write property="label" name="pagerItem"/>
>         </html:link>
>        </logic:equal>
>        <logic:equal value="true" property="isCurrent" name="pagerItem">
>         <bean:write property="label" name="pagerItem"/>
>        </logic:equal>
>       </td>
>      </logic:iterate>
>     <td>
>      <logic:equal value="true" property="hasNext" name="pager">
>       <html:link property="next.link" name="pager"
forward="news">Next</html:link>
>      </logic:equal>
>      <logic:equal value="false" property="hasNext"
name="pager">Next</logic:equal>
>     </td>
>    </tr>
>   </table>
>  </logic:greaterThan>
> </logicext:pager>
>
> <bean:write name="pagerPanel" filter="false"/>
>
> .... page of the list
>
> <bean:write name="pagerPanel" filter="false"/>
>
> --
> Best regards,
>  Oleg                          mailto:gonza@penza.net
>
>