Tutorial :Displaytag library - detecting a paging request



Question:

I'm currently developing a portlet for Liferay (using the Spring MVC framework). Now I just used the displaytag library for implementing paging on a list I'm displaying on the portlet.

My problem now is that I would need to detect whether the current request has been started by the paging control of the displaytag library. What I found is that when doing paging, a parameter is added in the URL that looks like "d-4157739-p=2" which indicates the current page that is shown. So I could do

int isPagingRequest = PortletRequestUtils.getIntParameter(request, "d-1332617-p", -1);  

..and if the isPagingRequest (which I could change to a boolean) has a value then the request has been initiated by the displaytag paging. This is however very bad coding so I'd like to avoid it. Moreover the number between the "d" and "p" varies which makes it really hard to detect it.

Does someone have a suggestion how I can detect whether the current request has been provocated by a paging??

Thanks a lot


Solution:1

Displaytag provides a class "ParamEncoder" that (I think its in its constructor) produces the checksums for you based off the table name of your table (the id or uid element - this must be set to produce valid checksums (the numbers between d and -(parameter)). Check it out. TableTagParameters includes the constants needed for the parameters as well - so with a combination of these two, you can retrieve the appropriate variable key to retrieve from the request.


Solution:2

One option could be to add your own parameter to the value in the requestURI attribute. So for example, you could add this:

requestURI="mylistsource.action?ispage=true"  

to the table tag, where mylistsource.action is your server action that generates the list in the first place.

On the server you can then look for the "ispage" parameter.


Solution:3

String param = new ParamEncoder(tableId).encodeParameterName(TableTagParameters.PARAMETER_PAGE)). . Above will solve your problem and also sums up what @MetroidFan2002 was saying.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »