我有一个关于primefaces datatable组件的问题。我希望将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变量被误认为字符串了?
感谢您的帮助。谢谢。
发布于 2012-03-23 22:02:49
java.lang.String不能强制转换为javax.faces.component.UIComponent。
binding属性必须引用UIComponent,而不是普通的String。实际上,您忘记了属性值周围的#{},这将使它被视为普通的String。
对其进行相应的修复:
binding="#{saProductCategoryController.dtProductCategory}"发布于 2012-03-23 22:03:58
替换
binding="saProductCategoryController.dtProductCategory"使用
binding="#{saProductCategoryController.dtProductCategory}"https://stackoverflow.com/questions/9840502
复制相似问题