使用org.primefaces.component.datatable.DataTable绑定primefaces dataTable;

时间:2012-03-23 14:01:33

标签: binding jsf-2 datatable primefaces

我对primefaces数据表组件有疑问。我想将一个DataTable变量绑定到p:dataTable,以便我能够从支持bean以编程方式操作第一行,rowsPerPageTemplate等。但是我陷入困境并且不断将java.lang.String转换为javax.faces.component.UIComponent。

这是我的p:dataTable声明。

<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">

这是我的ViewScoped支持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());
    }
}

可能是什么问题?似乎DataTable变量被误认为是String?

感谢您的所有帮助。感谢。

2 个答案:

答案 0 :(得分:5)

  

java.lang.String无法强制转换为javax.faces.component.UIComponent。

binding属性必须引用UIComponent,而不是普通的String。事实上,你忘记了属性值周围的#{},这会使它被视为普通的香草String

相应修复:

binding="#{saProductCategoryController.dtProductCategory}"

答案 1 :(得分:2)

替换

binding="saProductCategoryController.dtProductCategory"

binding="#{saProductCategoryController.dtProductCategory}"