简体   繁体   English

无法绑定rich:dataTable

[英]Trouble binding a rich:dataTable

I'm having some problems with defining a binding bean for my rich:dataTable. 我在为rich:dataTable定义绑定bean时遇到一些问题。

The contents of the datatable are already defined in the XHTML, I just want to use the binding to read the rows back later so that the table contents can be exported into a PDF. 数据表的内容已经在XHTML中定义,我只想使用绑定稍后再读回行,以便可以将表内容导出为PDF。

In my XHTML file, I put 在我的XHTML文件中,

<rich:dataTable ... binding="#{backingBean.tableBinding}">

Then, in my backing bean, I declare a member: 然后,在我的支持bean中,声明一个成员:

import org.richfaces.component.html.HtmlDataTable;
class BackingBean {
   private HtmlDataTable tableBinding ;
   public BackingBean() {
      tableBinding = new HtmlDataTable() ;
   }
   // ... (incl. getters and setters for binding)
 } ;

However, this results in: 但是,这导致:

java.lang.NullPointerException at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:809) javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:809)上的java.lang.NullPointerException

when I try to load the page. 当我尝试加载页面时。 Is there something I need to do with the HtmlDataTable variable besides simply constructing it? 除了简单地构造变量之外,我还需要对HtmlDataTable变量进行处理吗? Is it even possible to use the binding attribute in the way I intend here? 甚至可以按照我在此处使用的方式使用binding属性吗?

Don't create an instance of HtmlDataTable yourself in the constructor. 不要在构造函数中自己创建HtmlDataTable的实例。 RichFaces will create an instance and inject it to your BackingBean. RichFaces将创建一个实例并将其注入到您的BackingBean中。 All you need is an public getter and setter. 您只需要一个公共获取者和安装者即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM