DataTable With Paginator: Rows Don't Display After Update

UI Components for JSF
Post Reply
davecurryco
Posts: 19
Joined: 12 Nov 2010, 21:45

18 Nov 2010, 05:39

I believe that this is the same underlying problem as Issue 1371, which was closed with the status "Can't reproduce".

I am using PrimeFaces 2.2RC1 with Mojarra 2.0.3 on both Tomcat 6.0.29 and JBoss 4.2.2GA. I have a DataTable on a Facelets page. The value of the DataTable comes from a List property of a SessionScope backing bean. In the same Form, I have an InputText control and a CommandButton with an action property that invokes a method of the backing bean. This method takes the value of the InputText, uses it as a search criteria, and replaces the List with a new List comprised of elements that match the criteria. This works fine when the entire DataTable is displayed, or when the DataTable uses a scroller. However, when the DataTable uses a paginator an issue occurs. If the original List contains more than a single page of results and if the user selects a page other than the first page before entering a search criteria value and clicking the CommandButton, the resulting DataTable will not display any rows -- even though the paginator control indicates that one or more pages of elements were found in the List. Using Firebug, one can see that the TBODY element generated by the DataTable is empty. However, if the user takes an action that refreshes the DataTable on the client (for example, changing the RowsPerPage selection), the DataTable will display the missing rows. The issue does not happen if the user selects the first page before performing the search action.

I have a complete example program that exhibits the failure every time, which I can post if necessary. However, here are the relevant snippets of the code:

Facelets View: chemicalElementList.xhtml

Code: Select all

<h:form>
<h:panelGrid columns="3">
    <h:outputText value="Search:"/>
    <h:inputText value="#{chemicalElementListBean.searchString}"/>
    <h:commandButton value="Go" action="#{chemicalElementListBean.doSearch}" />
</h:panelGrid>
<p:dataTable id="elementsTable"
    value="#{chemicalElementListBean.chemicalElements}"
    var="ce"
    paginator="true" rows="10"
    paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
    rowsPerPageTemplate="5,10,15">
    <!-- column definitions -->
</p:dataTable>
</h:form>
ManagedBean: ChemicalElementListBean.java

Code: Select all

@ManagedBean
@SessionScoped
public class ChemicalElementListBean implements Serializable {
    private static final long serialVersionUID = 1L;

    @ManagedProperty(value="#{chemicalElementService}")
    private ChemicalElementService chemicalElementService;
	
    private List<ChemicalElement> chemicalElements;
    private String searchString;

    public String doSearch() {
        chemicalElements = search();
        return "";
    }
	
    private List<ChemicalElement> search() {
        List<ChemicalElement> list = new ArrayList<ChemicalElement>();
        ChemicalElement element = chemicalElementService.findBySymbol(searchString.trim());
        if (element != null) {
            list.add(element);
            return list;
        }
	return list;
    }

    // Getters and setters
}	
I had experienced a similar problem with OpenFaces 2.x some time ago, so I tried clearing the List and replacing only its elements as so:

Code: Select all

    private List<ChemicalElement> chemicalElements = new ArrayList<ChemicalElement>();
    ...
    public String doSearch() {
        chemicalElements.clear();
        chemicalElements.addAll(search());		
        return "";
    }
Alas, this was to no avail. The problem still happens and I am out of ideas for work-arounds.

callahan
Posts: 768
Joined: 27 May 2010, 22:52

18 Nov 2010, 13:12

Does it work if you set the dataTables page and first attributes to the appropriate values before doSearch returns? An example can be seen here: http://primefaces.prime.com.tr/forum/vi ... f=3&t=5848. After doing a search, you could jump to the first page.

davecurryco
Posts: 19
Joined: 12 Nov 2010, 21:45

18 Nov 2010, 18:41

I added the following code to the action method:

Code: Select all

public String doSearch() {
    chemicalElements = search();
    DataTable dt = (DataTable)FacesContext.getCurrentInstance().getViewRoot().findComponent("form:elementsTable");
    dt.setPage(0);
    dt.setFirst(0);

    return "";
}
The DataTable is now displaying the rows after the search as expected. Thanks!

In reading Issue 1386, I think that I understand the reasoning behind the "Won't Fix" status. I would agree with timotius that a tag attribute such as

Code: Select all

<p:datatable resetPagination="true">
would be useful. The presence of the attribute and corresponding documentation would prompt developers to consider something that would otherwise be a stumbling-block. It would also give developers the option to avoid a backing-bean dependency on PrimeFaces.

As I mentioned, I have a stand-alone example that I could include in the issue report if it would be useful.

Thanks Again!

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 22 guests