我有一个关于素数面数据表组件的问题。我想将一个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支持豆。
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不能强制转换为javax.faces.component.UIComponent.
binding
属性必须引用UIComponent
,而不是普通的String
。实际上,您忘记了属性值周围的#{}
,这将使它被视为普通的String
。
相应地修复:
binding="#{saProductCategoryController.dtProductCategory}"
更换
binding="saProductCategoryController.dtProductCategory"
带有
binding="#{saProductCategoryController.dtProductCategory}"