gpt4 book ai didi

将 primefaces dataTable 与 org.primefaces.component.datatable.DataTable 绑定(bind);

转载 作者:行者123 更新时间:2023-12-03 03:44:36 27 4
gpt4 key购买 nike

我有一个关于 primefaces 数据表组件的问题。我想将 DataTable 变量绑定(bind)到 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?

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

最佳答案

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

绑定(bind)属性必须引用UIComponent,而不是普通的String。事实上,您忘记了属性值周围的 #{},这会使其被视为普通的 String

相应地修复它:

binding="#{saProductCategoryController.dtProductCategory}"

关于将 primefaces dataTable 与 org.primefaces.component.datatable.DataTable 绑定(bind);,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9840502/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com