Displaytag struts 2 go to specific page

2020-02-13 06:25发布

问题:

in my project i'm using display tag. The problem comes when the results returned are like e.g. 300 pages. The user needs to jump to page e.g. 200 but he can't. He needs to go slowly there ( 5 pages at a time or so ). I want to add the ability to the user to choose in a drop-down the page he wants to jump to. Is there any property in display-tag or any suggestion?

回答1:

You need to use ParamEncoder to get the name (and eventually the value) of displayTag's parameters, specified in TableTagParameters.html, in your case PARAMETER_PAGE.

<div>
    With Scriptlets 
    <br/>
    <% String pageNumParameter = 
              new org.displaytag.util.ParamEncoder("id_of_your_displaytag_table").encodeParameterName(org.displaytag.tags.TableTagParameters.PARAMETER_PAGE); %>
    [parameter name] = <%= pageNumParameter %>
    <br/>
    [parameter value]= <%= request.getParameter(pageNumParameter) %> 
</div>

<div>
    With OGNL
    <br/>   
    <s:set var="pageNumParameter" 
           value="%{new org.displaytag.util.ParamEncoder('id_of_your_displaytag_table').encodeParameterName(@org.displaytag.tags.TableTagParameters@PARAMETER_PAGE)}" />        
    [parameter name] = <s:property value="%{#pageNumParameter}"/>
    <br/>
    [parameter value]= <s:property value="#parameters[#pageNumParameter]"/>
</div>

Then you should be able to craft a request by passing the dynamic generated parameter for that table, with the value you want (from a SelectBox, from an Input Text, from a script etc)