【问题标题】:Binding primefaces dataTable with org.primefaces.component.datatable.DataTable;将 primefaces 数据表与 org.primefaces.component.datatable.DataTable 绑定;
【发布时间】:2012-04-08 02:09:28
【问题描述】:

我有一个关于 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?

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

【问题讨论】:

    标签: binding jsf-2 datatable primefaces


    【解决方案1】:

    java.lang.String 不能转换为 javax.faces.component.UIComponent。

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

    相应地修复它:

    binding="#{saProductCategoryController.dtProductCategory}"
    

    【讨论】:

      【解决方案2】:

      替换

      binding="saProductCategoryController.dtProductCategory"
      

      binding="#{saProductCategoryController.dtProductCategory}"
      

      【讨论】:

      • 谢谢马特。知道了。太多的代码,我错过了显而易见的。谢谢
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-09
      • 1970-01-01
      • 2011-04-02
      • 1970-01-01
      • 2016-03-12
      • 2016-03-14
      • 1970-01-01
      相关资源
      最近更新 更多