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.
我正在为Liferay开发一个portlet(使用Spring MVC框架)。现在我只使用displaytag库在我正在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
我现在的问题是我需要检测当前请求是否已由displaytag库的分页控件启动。我发现在进行分页时,会在URL中添加一个参数,该参数看起来像“d-4157739-p = 2”,表示显示的当前页面。所以我能做到
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.
..如果isPagingRequest(我可以改为布尔值)有一个值,则该请求已由displaytag分页启动。然而,这是非常糟糕的编码,所以我想避免它。此外,“d”和“p”之间的数字不同,这使得它很难被检测到。
Does someone have a suggestion how I can detect whether the current request has been provocated by a paging??
有人有一个建议我如何检测当前请求是否已被分页挑出?
Thanks a lot
非常感谢
3 个解决方案
#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.
Displaytag提供了一个类“ParamEncoder”(我认为它在它的构造函数中)根据表的表名(id或uid元素)为你生成校验和 - 这必须设置为生成有效的校验和(d和d之间的数字) - (参数))。检查出来.TableTagParameters包括参数所需的常量 - 因此,结合这两个,您可以检索相应的变量键以从请求中检索。
#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属性中的值。例如,您可以添加以下内容:
requestURI="mylistsource.action?ispage=true"
to the table tag, where mylistsource.action is your server action that generates the list in the first place.
到表标记,其中mylistsource.action是您首先生成列表的服务器操作。
On the server you can then look for the "ispage" parameter.
然后,在服务器上,您可以查找“ispage”参数。
#3
String param = new ParamEncoder(tableId).encodeParameterName(TableTagParameters.PARAMETER_PAGE)). . Above will solve your problem and also sums up what @MetroidFan2002 was saying.
String param = new ParamEncoder(tableId).encodeParameterName(TableTagParameters.PARAMETER_PAGE))。 。以上将解决您的问题,并总结@ MetroidFan2002所说的内容。
#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.
Displaytag提供了一个类“ParamEncoder”(我认为它在它的构造函数中)根据表的表名(id或uid元素)为你生成校验和 - 这必须设置为生成有效的校验和(d和d之间的数字) - (参数))。检查出来.TableTagParameters包括参数所需的常量 - 因此,结合这两个,您可以检索相应的变量键以从请求中检索。
#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属性中的值。例如,您可以添加以下内容:
requestURI="mylistsource.action?ispage=true"
to the table tag, where mylistsource.action is your server action that generates the list in the first place.
到表标记,其中mylistsource.action是您首先生成列表的服务器操作。
On the server you can then look for the "ispage" parameter.
然后,在服务器上,您可以查找“ispage”参数。
#3
String param = new ParamEncoder(tableId).encodeParameterName(TableTagParameters.PARAMETER_PAGE)). . Above will solve your problem and also sums up what @MetroidFan2002 was saying.
String param = new ParamEncoder(tableId).encodeParameterName(TableTagParameters.PARAMETER_PAGE))。 。以上将解决您的问题,并总结@ MetroidFan2002所说的内容。