首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用org.primefaces.component.datatable.DataTable绑定primefaces dataTable;

用org.primefaces.component.datatable.DataTable绑定primefaces dataTable;
EN

Stack Overflow用户
提问于 2012-03-23 22:01:33
回答 2查看 17.8K关注 0票数 2

我有一个关于primefaces datatable组件的问题。我希望将DataTable变量绑定到p:dataTable,以便能够从支持bean以编程方式操作第一个、行、rowsPerPageTemplate等。但是我被卡住了,并且不断得到java.lang.String不能被转换为javax.faces.component.UIComponent。

下面是我的p:dataTable声明。

代码语言:javascript
复制
<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。

代码语言:javascript
复制
    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变量被误认为字符串了?

感谢您的帮助。谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-03-23 22:02:49

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

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

对其进行相应的修复:

代码语言:javascript
复制
binding="#{saProductCategoryController.dtProductCategory}"
票数 5
EN

Stack Overflow用户

发布于 2012-03-23 22:03:58

替换

代码语言:javascript
复制
binding="saProductCategoryController.dtProductCategory"

使用

代码语言:javascript
复制
binding="#{saProductCategoryController.dtProductCategory}"
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9840502

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档