将Primefaces DataTable与org.primefaces.component.datatable.DataTable绑定;
我对primefaces数据表组件有疑问.我想将DataTable变量绑定到p:dataTable,这样我就可以通过编程从后备bean中操作第一个,行,rowsPerPageTemplate等.但是我被困住了,并不断获取java.lang.String无法转换为javax.faces.component.UIComponent.
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.
这是我的p:dataTable声明.
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">
这是我的ViewScoped支持bean.
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());
}
}
可能是什么问题?看来DataTable变量被误认为是字符串?
What could be the problem? It seems that the DataTable variable is mistaken for a String?
感谢您的所有帮助.谢谢.
Appreciate all your help. Thanks.
java.lang.String无法转换为javax.faces.component.UIComponent.
java.lang.String cannot be cast to javax.faces.component.UIComponent.
binding
属性必须引用UIComponent
,而不是普通香草String
.的确,您忘记了属性值周围的#{}
,因此将其视为普通香草String
.
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
.
相应修复:
binding="#{saProductCategoryController.dtProductCategory}"