开发者

Datatable paginator is not displayed

I am making a very simple datatable with JSF 2.0 tag dataTable but for some reason the page paginator is not displayed. Why is that?

<p:dataTable var="garbage" value="#{resultsController.allGarbage}" paginator="true" rows="10">          

            <p:column>  
            <f:facet name="header">  
            <h:outputText value="Filename" />  
            </f:facet>  
            <h:out开发者_如何学运维putText value="#{garbage.filename}" />
             </p:column> 

            <p:column>  
            <f:facet name="header">  
            <h:outputText value="Description" />  
            </f:facet>  
            <h:outputText value="#{garbage.description}" />  
             </p:column> 

            <p:column>  
            <f:facet name="header">  
            <h:outputText value="Upload date" />  
            </f:facet>  
            <h:outputText value="#{garbage.uploadDate}" /> 
             </p:column>                
    </p:dataTable> 


Use p:dataTable instead of h:dataTable.

The pagination only works with the primefaces dataTable and not with the plain jsf dataTable.


The paginatorAlwaysVisible is an attribute of the primefaces datatable implementation, so you would have to use the datatable tag from the primefaces namespace: p:dataTable.

Edit: Also, you need a h:head element defined in your page, so that the jsf impl knows where to output additional scripts and stylesheets. If that is the case you should be seeing an error message like:

One or more resources have the target of 'head', but no 'head' component has been defined within the view.

To help debuging you could add the following context parameter to your web.xml:

<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>


@sfrj: You probably need something like this:

<p:dataTable var="garbage" value="#{resultsController.allGarbage}" paginator="true" rows="10" paginatorPosition="bottom" paginatorTemplate="{FirstPageLink} {PageLinks} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="5,10,15,20" paginatorAlwaysVisible="false">

paginator="true" only tells the p:dataTable component that you want the paginator control but you haven't specified what you want in it yet. Hence, you need the paginatorTemplate attribute. The paginatorAlwaysVisible="false" attribute is good aesthetically if your query returns no record - in which case, the paginator section won't be shown if there are no record. Else, it's visible if there is at least one record returned from your query.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜