You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by deepak va <de...@hotmail.com> on 2007/05/01 22:24:04 UTC

AbstractPagerTool

Hi ,

Iam using the AbstractPagerTool for pagination.

I have written a Test class which extends AbstractPagerTool. Test class has 
the below code.
For every click on the pagination link a call is made to the database for 
fetching the records.
This is not the expected behaviour. We want to get the values once from the 
database and use it subsequently.

Please suggest how to achieve this.


*****************************************
public void setup(HttpServletRequest req)
	{
		        ParameterParser pp = new ParameterParser(req);
			setIndex(pp.getInt("index",0));
			setItemsPerPage(pp.getInt("show", 10));

			setSlipSize(10);

		List tradelist = getDataFromDatabase();
			setItems(tradelist);


	}


**************************************

Regards
Deepak

_________________________________________________________________
Sign in and get updated on all the action from Formula One 
http://content.msn.co.in/Sports/FormulaOne/Default


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: AbstractPagerTool

Posted by deepak va <de...@hotmail.com>.
thanks a lot it worked....


>From: "Nathan Bubna" <nb...@gmail.com>
>Reply-To: "Velocity Users List" <us...@velocity.apache.org>
>To: "Velocity Users List" <us...@velocity.apache.org>
>Subject: Re: AbstractPagerTool
>Date: Wed, 2 May 2007 12:33:54 -0700
>
>On 5/2/07, deepak va <de...@hotmail.com> wrote:
>>please let me know what you meant by "if there is an HttpSession for the
>>request" .
>>How so i set the same.
>
>are you familiar with the servlet API?
>http://java.sun.com/products/servlet/2.5/docs/servlet-2_5-mr2/index.html
>
>Specifically, you should read:
>http://java.sun.com/products/servlet/2.5/docs/servlet-2_5-mr2/javax/servlet/http/HttpSession.html
>
>>I modified the code as below. But for every request the 
>>setItems(tradelist)
>>is getting called.
>>
>>Please suggest what iam missing.
>
>try adding:
>
>this.session = request.getSession(true);
>
>before the call to setItems(tradelist);
>
>>
>> >From: "Nathan Bubna" <nb...@gmail.com>
>> >Reply-To: "Velocity Users List" <us...@velocity.apache.org>
>> >To: "Velocity Users List" <us...@velocity.apache.org>
>> >Subject: Re: AbstractPagerTool
>> >Date: Tue, 1 May 2007 14:09:52 -0700
>> >
>> >setup(HttpServletRequest) is called every request.  you only want to
>> >call setItems() once per list being paginated.   if there is an
>> >HttpSession for the request, then the call to setItems() will try to
>> >store the item list in the session.  this would then let you do:
>> >
>> >public void setup(HttpServletRequest req)
>> >       {
>> >                       ParameterParser pp = new ParameterParser(req);
>> >                       setIndex(pp.getInt("index",0));
>> >                       setItemsPerPage(pp.getInt("show", 10));
>> >
>> >                       setSlipSize(10);
>> >
>> >                       if (!hasItems()) {
>> >                            List tradelist = getDataFromDatabase();
>> >                            setItems(tradelist);
>> >                       }
>> >       }
>> >
>> >in general, though, it is up to you to see that setItems() isn't
>> >called on every request.  the solution above will work if the item
>> >list never changes, but they often do.  so, you'll probably also want
>> >to create some hook to refresh the item list when appropriate.
>> >
>> >
>> >On 5/1/07, deepak va <de...@hotmail.com> wrote:
>> >>Hi ,
>> >>
>> >>Iam using the AbstractPagerTool for pagination.
>> >>
>> >>I have written a Test class which extends AbstractPagerTool. Test class
>> >>has
>> >>the below code.
>> >>For every click on the pagination link a call is made to the database 
>>for
>> >>fetching the records.
>> >>This is not the expected behaviour. We want to get the values once from
>> >>the
>> >>database and use it subsequently.
>> >>
>> >>Please suggest how to achieve this.
>> >>
>> >>
>> >>*****************************************
>> >>public void setup(HttpServletRequest req)
>> >>         {
>> >>                         ParameterParser pp = new ParameterParser(req);
>> >>                         setIndex(pp.getInt("index",0));
>> >>                         setItemsPerPage(pp.getInt("show", 10));
>> >>
>> >>                         setSlipSize(10);
>> >>
>> >>                 List tradelist = getDataFromDatabase();
>> >>                         setItems(tradelist);
>> >>
>> >>
>> >>         }
>> >>
>> >>
>> >>**************************************
>> >>
>> >>Regards
>> >>Deepak
>> >>
>> >>_________________________________________________________________
>> >>Sign in and get updated on all the action from Formula One
>> >>http://content.msn.co.in/Sports/FormulaOne/Default
>> >>
>> >>
>> >>---------------------------------------------------------------------
>> >>To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> >>For additional commands, e-mail: user-help@velocity.apache.org
>> >>
>> >>
>> >
>> >---------------------------------------------------------------------
>> >To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> >For additional commands, e-mail: user-help@velocity.apache.org
>> >
>>
>>_________________________________________________________________
>>Sign in and get updated on all the action from Formula One
>>http://content.msn.co.in/Sports/FormulaOne/Default
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>>For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>For additional commands, e-mail: user-help@velocity.apache.org
>

_________________________________________________________________
Best Hotel Deals. Click here Now http://ss1.richmedia.in/recurl.asp?pid=19


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: AbstractPagerTool

Posted by Nathan Bubna <nb...@gmail.com>.
On 5/2/07, deepak va <de...@hotmail.com> wrote:
> please let me know what you meant by "if there is an HttpSession for the
> request" .
> How so i set the same.

are you familiar with the servlet API?
http://java.sun.com/products/servlet/2.5/docs/servlet-2_5-mr2/index.html

Specifically, you should read:
http://java.sun.com/products/servlet/2.5/docs/servlet-2_5-mr2/javax/servlet/http/HttpSession.html

> I modified the code as below. But for every request the setItems(tradelist)
> is getting called.
>
> Please suggest what iam missing.

try adding:

this.session = request.getSession(true);

before the call to setItems(tradelist);

>
> >From: "Nathan Bubna" <nb...@gmail.com>
> >Reply-To: "Velocity Users List" <us...@velocity.apache.org>
> >To: "Velocity Users List" <us...@velocity.apache.org>
> >Subject: Re: AbstractPagerTool
> >Date: Tue, 1 May 2007 14:09:52 -0700
> >
> >setup(HttpServletRequest) is called every request.  you only want to
> >call setItems() once per list being paginated.   if there is an
> >HttpSession for the request, then the call to setItems() will try to
> >store the item list in the session.  this would then let you do:
> >
> >public void setup(HttpServletRequest req)
> >       {
> >                       ParameterParser pp = new ParameterParser(req);
> >                       setIndex(pp.getInt("index",0));
> >                       setItemsPerPage(pp.getInt("show", 10));
> >
> >                       setSlipSize(10);
> >
> >                       if (!hasItems()) {
> >                            List tradelist = getDataFromDatabase();
> >                            setItems(tradelist);
> >                       }
> >       }
> >
> >in general, though, it is up to you to see that setItems() isn't
> >called on every request.  the solution above will work if the item
> >list never changes, but they often do.  so, you'll probably also want
> >to create some hook to refresh the item list when appropriate.
> >
> >
> >On 5/1/07, deepak va <de...@hotmail.com> wrote:
> >>Hi ,
> >>
> >>Iam using the AbstractPagerTool for pagination.
> >>
> >>I have written a Test class which extends AbstractPagerTool. Test class
> >>has
> >>the below code.
> >>For every click on the pagination link a call is made to the database for
> >>fetching the records.
> >>This is not the expected behaviour. We want to get the values once from
> >>the
> >>database and use it subsequently.
> >>
> >>Please suggest how to achieve this.
> >>
> >>
> >>*****************************************
> >>public void setup(HttpServletRequest req)
> >>         {
> >>                         ParameterParser pp = new ParameterParser(req);
> >>                         setIndex(pp.getInt("index",0));
> >>                         setItemsPerPage(pp.getInt("show", 10));
> >>
> >>                         setSlipSize(10);
> >>
> >>                 List tradelist = getDataFromDatabase();
> >>                         setItems(tradelist);
> >>
> >>
> >>         }
> >>
> >>
> >>**************************************
> >>
> >>Regards
> >>Deepak
> >>
> >>_________________________________________________________________
> >>Sign in and get updated on all the action from Formula One
> >>http://content.msn.co.in/Sports/FormulaOne/Default
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> >>For additional commands, e-mail: user-help@velocity.apache.org
> >>
> >>
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> >For additional commands, e-mail: user-help@velocity.apache.org
> >
>
> _________________________________________________________________
> Sign in and get updated on all the action from Formula One
> http://content.msn.co.in/Sports/FormulaOne/Default
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: AbstractPagerTool

Posted by deepak va <de...@hotmail.com>.
please let me know what you meant by "if there is an HttpSession for the 
request" .
How so i set the same.

I modified the code as below. But for every request the setItems(tradelist) 
is getting called.

Please suggest what iam missing.



>From: "Nathan Bubna" <nb...@gmail.com>
>Reply-To: "Velocity Users List" <us...@velocity.apache.org>
>To: "Velocity Users List" <us...@velocity.apache.org>
>Subject: Re: AbstractPagerTool
>Date: Tue, 1 May 2007 14:09:52 -0700
>
>setup(HttpServletRequest) is called every request.  you only want to
>call setItems() once per list being paginated.   if there is an
>HttpSession for the request, then the call to setItems() will try to
>store the item list in the session.  this would then let you do:
>
>public void setup(HttpServletRequest req)
>       {
>                       ParameterParser pp = new ParameterParser(req);
>                       setIndex(pp.getInt("index",0));
>                       setItemsPerPage(pp.getInt("show", 10));
>
>                       setSlipSize(10);
>
>                       if (!hasItems()) {
>                            List tradelist = getDataFromDatabase();
>                            setItems(tradelist);
>                       }
>       }
>
>in general, though, it is up to you to see that setItems() isn't
>called on every request.  the solution above will work if the item
>list never changes, but they often do.  so, you'll probably also want
>to create some hook to refresh the item list when appropriate.
>
>
>On 5/1/07, deepak va <de...@hotmail.com> wrote:
>>Hi ,
>>
>>Iam using the AbstractPagerTool for pagination.
>>
>>I have written a Test class which extends AbstractPagerTool. Test class 
>>has
>>the below code.
>>For every click on the pagination link a call is made to the database for
>>fetching the records.
>>This is not the expected behaviour. We want to get the values once from 
>>the
>>database and use it subsequently.
>>
>>Please suggest how to achieve this.
>>
>>
>>*****************************************
>>public void setup(HttpServletRequest req)
>>         {
>>                         ParameterParser pp = new ParameterParser(req);
>>                         setIndex(pp.getInt("index",0));
>>                         setItemsPerPage(pp.getInt("show", 10));
>>
>>                         setSlipSize(10);
>>
>>                 List tradelist = getDataFromDatabase();
>>                         setItems(tradelist);
>>
>>
>>         }
>>
>>
>>**************************************
>>
>>Regards
>>Deepak
>>
>>_________________________________________________________________
>>Sign in and get updated on all the action from Formula One
>>http://content.msn.co.in/Sports/FormulaOne/Default
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>>For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>For additional commands, e-mail: user-help@velocity.apache.org
>

_________________________________________________________________
Sign in and get updated on all the action from Formula One 
http://content.msn.co.in/Sports/FormulaOne/Default


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: AbstractPagerTool

Posted by Nathan Bubna <nb...@gmail.com>.
setup(HttpServletRequest) is called every request.  you only want to
call setItems() once per list being paginated.   if there is an
HttpSession for the request, then the call to setItems() will try to
store the item list in the session.  this would then let you do:

public void setup(HttpServletRequest req)
       {
                       ParameterParser pp = new ParameterParser(req);
                       setIndex(pp.getInt("index",0));
                       setItemsPerPage(pp.getInt("show", 10));

                       setSlipSize(10);

                       if (!hasItems()) {
                            List tradelist = getDataFromDatabase();
                            setItems(tradelist);
                       }
       }

in general, though, it is up to you to see that setItems() isn't
called on every request.  the solution above will work if the item
list never changes, but they often do.  so, you'll probably also want
to create some hook to refresh the item list when appropriate.


On 5/1/07, deepak va <de...@hotmail.com> wrote:
> Hi ,
>
> Iam using the AbstractPagerTool for pagination.
>
> I have written a Test class which extends AbstractPagerTool. Test class has
> the below code.
> For every click on the pagination link a call is made to the database for
> fetching the records.
> This is not the expected behaviour. We want to get the values once from the
> database and use it subsequently.
>
> Please suggest how to achieve this.
>
>
> *****************************************
> public void setup(HttpServletRequest req)
>         {
>                         ParameterParser pp = new ParameterParser(req);
>                         setIndex(pp.getInt("index",0));
>                         setItemsPerPage(pp.getInt("show", 10));
>
>                         setSlipSize(10);
>
>                 List tradelist = getDataFromDatabase();
>                         setItems(tradelist);
>
>
>         }
>
>
> **************************************
>
> Regards
> Deepak
>
> _________________________________________________________________
> Sign in and get updated on all the action from Formula One
> http://content.msn.co.in/Sports/FormulaOne/Default
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org