2012-03-23 119 views
3

我有一个关于primefaces数据表组件的问题。我想将一个DataTable变量绑定到p:dataTable,这样我就可以通过支持bean以编程方式操作第一行,rowsPerPageTemplate等。但是我被卡住了,继续得到java.lang.String不能转换为javax.faces.component.UIComponent。使用org.primefaces.component.datatable.DataTable绑定primefaces dataTable;

这是我的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?

感谢您的帮助。谢谢。

回答

5

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

binding属性必须引用一个UIComponent,不是普通香草String。事实上,你忘记了围绕属性值的#{},这将使其被视为普通香草String

修复它的相应:

binding="#{saProductCategoryController.dtProductCategory}" 
+0

OMG我的眼睛已经眯起眼睛。感谢BalusC。 – frazkok 2012-03-23 14:12:04

2

更换

binding="saProductCategoryController.dtProductCategory" 

binding="#{saProductCategoryController.dtProductCategory}" 
+0

谢谢马特。得到它了。代码太多,我错过了显而易见的。谢谢 – frazkok 2012-03-23 14:14:49