有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Primefaces Datatable在触发操作时提供空指针异常

我试图使用datatable组件,但在selection属性中使用数组而不是对象 Here is the sample from Primefaces showcase

我的域名是EfaDocLabelModel,我将CarDataModel(从showcase)更新为EfaDocLabelModel以下是代码

public EfaDocLabelModel() {
}
public EfaDocLabelModel(List<EfaDocLabelMatch> data) {
    super(data);
}
@Override
public EfaDocLabelMatch getRowData(String rowKey) {
      List<EfaDocLabelMatch> docLabelList = (List<EfaDocLabelMatch>) getWrappedData();
    for (EfaDocLabelMatch docLabel : docLabelList) {
        if (docLabel.getDoclabelId().toString().equals(rowKey)) {
            return docLabel;
        }
    }
    return null;
}
@Override
public Object getRowKey(EfaDocLabelMatch docLabel) {
    return docLabel.getDoclabelId();

}

在我的托管bean中,当用户在数据表的页脚部分触发commandbutton时 我试图获得选中的行,但它给出

java.lang.NullPointerException
at java.lang.reflect.Array.newArray(Native Method)
at java.lang.reflect.Array.newInstance(Array.java:70)
at org.primefaces.component.datatable.feature.SelectionFeature.decodeMultipleSelection(SelectionFeature.java:53)
at org.primefaces.component.datatable.feature.SelectionFeature.decode(SelectionFeature.java:39)
at org.primefaces.component.datatable.DataTableRenderer.decode(DataTableRenderer.java:53)

我可以从showcase中运行多个选择,其中使用了CarDataModel,但在根据需要修改时使用了相同的结构,我发现了此错误

这是我的豆子

public class DocLabelBean implements Serializable {
private List<EfaDocLabelMatch> docLabelMatchList;
private EfaDocLabelMatch[] docLabelArray;


    public String updateLabel() {
    EfaDocLabelMatch[] selectedDocArray = getDocLabelArray();//I m sure I m 
    //getting error because selectedDocArray is null. 
    DTO result = new DTO();
    for (EfaDocLabelMatch docLabel : selectedDocArray) {
    }

以下是我的页面必需的代码:

<p:dataTable emptyMessage="No Labeled Doc" 
 var="docLabel" value="#{docLabelBean.docLabelModel}" 
 selection="#{docLabelBean.docLabelArray}"> 
 <p:column selectionMode="multiple"  />
 <p:column headerText="Id" >  
 #{docLabel.doclabelId} 
 </p:column>  
 <p:column headerText="Doc No" >  
 #{docLabel.documentId}  
 </p:column>  
 <p:column headerText="Label Key" >  
 #{docLabel.docLabelKey}  
 </p:column>

和第页的commanbutton代码:

<p:commandButton value="Sil" icon="ui-icon-search"  
update="@form"  process="@form"
action="#{docLabelBean.updateLabel()}" /> 

我尝试了ajax=false和balusc提到的其他可能的错误原因,但仍然无法解决问题 这是 Bug report。我需要将选定的行分配给一个列表或数组,如果这是一个真正的错误,还有其他方法吗


共 (0) 个答案