2
votes

I have a question regarding primefaces datatable component. I want to bind a DataTable variable to the p:dataTable so that I would be able to manipulate the first, rows, rowsPerPageTemplate, etc. programmatically from the backing bean. But I'm stuck and keep getting java.lang.String cannot be cast to javax.faces.component.UIComponent.

Here's my p:dataTable declaration.

<p:dataTable id="dtProductCategoryList" value="#{saProductCategoryController.saproductcategories}" rowsPerPageTemplate="#{appConfig.rowsPerPageTemplate}" 
                             paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}" 
                             currentPageReportTemplate="{currentPage} #{bundle.DataTablePageSeparator} {totalPages}"
                             paginatorAlwaysVisible="false" var="item" paginator="true" rows="#{appConfig.rowsPerPageDefault}"
                             binding="saProductCategoryController.dtProductCategory">

And here's my ViewScoped backing bean.

    private DataTable dtProductCategory;

/** Creates a new instance of saProductCategoryController */
public SaProductCategoryController() {
}

@PostConstruct
public void Init() {
    try {
        dtProductCategory = new DataTable();
        //dtProductCategory.
        saproductcategories = saProductCategoryFacade.selectAll();            
        LogController.log.info("Creating postconstruct for saProductCategoryController");
    } catch (Exception ex) {
        LogController.log.fatal(ex.toString());
    }
}

What could be the problem? It seems that the DataTable variable is mistaken for a String?

Appreciate all your help. Thanks.

2

2 Answers

5
votes

java.lang.String cannot be cast to javax.faces.component.UIComponent.

The binding attribute must refer an UIComponent, not a plain vanilla String. And indeed, you forgot the #{} around the attribute value which would make it to be treated as a plain vanilla String.

Fix it accordingly:

binding="#{saProductCategoryController.dtProductCategory}"
3
votes

Replace

binding="saProductCategoryController.dtProductCategory"

with

binding="#{saProductCategoryController.dtProductCategory}"