Question

Using the DisplayTag library with Struts 2 and external sorting (PaginatedLists) works great on my project.

Unfortunately, when I send to DisplayTag a non Paginated list and try to let DisplayTag to do the pagination, that is where the problems raise.

Currently, I can navigate to all pages of the results that I have without any problem. I am facing problems when I submit again the form to Struts to get the new results. Then the DisplayTag does not reset its page number to 1 but remains on the page it was on my last page selection and retains it.

So my list contains now different amount of data but DisplayTag is still showing on the page that i was before.

I got with request.getParameter("d-16544-p") the current page number and tried to reset this manually to 1 with no luck.

Also the

(Integer.parseInt
    (request.getParameter(
        (new ParamEncoder(tableId)
                         .encodeParameterName(TableTagParameters.PARAMETER_PAGE)
        )            
    )) - 1 ) * pageSize 

suggested in the DisplayTag docs did not really help much.

So my question is, how is it possible to reset Displaytag to go to page "1" after I submit a new request to a Struts 2 action and get back the results.

Was it helpful?

Solution

Finally fixed that with a workaround. Since i have two displaytag tables on the same page, it was more complicated than expected.

I added on the displaytag the clearStatus="${clear1Status}", where clear1Statusis the status of the first table.

Then had to add some extra code on my jsp

    <%
    String firstNumParameter =  new org.displaytag.util.ParamEncoder("tableRow").encodeParameterName(org.displaytag.tags.TableTagParameters.PARAMETER_PAGE);

    if(request.getParameter(firstNumParameter ) == null) {
        pageContext.setAttribute("clear1Status", "true");

    }else{
        pageContext.setAttribute("clear1Status", "false");
    }
%>

That solved my problem. At least in my scenario.

OTHER TIPS

I use clearStatus attribute of <display:table>:

<display:table id="${tableId}" class="displaytag" clearStatus="${param['filter'] != null}" 
    excludedParams="filter" keepStatus="true" name="${employListForm.persons}"
    pagesize="20" requestURI="employlist/personsList.jsp" summary="Employees">
  <display:column class="selectPerson" title="Edit">
    <t:popup styleClass="button"
        href="${editUrl}&amp;personIndex=${pageScope[tableRowNum]}">
      <t:icon name="edit" alt="Edit" title="Edit" />
    </t:popup>
  </display:column>
  <display:column property="specialityName" title="Speciality" />
  <display:column property="name" title="Name" />
  <display:column property="statusWorkName" title="Status" />
</display:table>

When this JSP is rendered after form submitting (either plain submit or AJAX request - doesn't matter), and form (request) has special parameter named filter, then fragment clearStatus="${param['filter'] != null}" instructs DisplayTag to clear its stored page number/etc., and start from first page.

When you are just paging/re-sorting, then request does not have such parameter.

I hope you've got the idea: check either for specific request parameter (if you already have it), or check for some flag in request/session attributes which your server code should set if page reset is needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top