JSF PrimeFaces在单视图排序NPE焦点问题上有多个数据表

时间:2019-02-05 12:02:21

标签: jsf primefaces

PrimeFaces数据表有问题。

我的情况: 在一个视图上有4个数据表。我只能排序最后一个。我认为这是某种关注。单击其他表上的列标题会导致以下NPE:

05-Feb-2019 11:55:03.542 SEVERE [http-nio-8080-exec-7] org.primefaces.application.exceptionhandler.PrimeExceptionHandler.logException null
 java.lang.NullPointerException
    at org.primefaces.component.datatable.DataTable.findColumnInGroup(DataTable.java:962)
    at org.primefaces.component.datatable.DataTable.findColumn(DataTable.java:953)
    at org.primefaces.component.datatable.feature.SortFeature.decode(SortFeature.java:86)
    at org.primefaces.component.datatable.DataTableRenderer.decode(DataTableRenderer.java:64)
    at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:478)
    at org.primefaces.component.api.UIData.processDecodes(UIData.java:287)
    at org.apache.myfaces.context.servlet.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:775)
    at org.apache.myfaces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:213)
    at org.primefaces.component.api.UIData.visitTree(UIData.java:827)
    at javax.faces.component.UIForm.visitTree(UIForm.java:345)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1044)
    at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1191)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1044)
    at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1191)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1044)
    at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1191).......

每个视图的代码类似于以下内容-它们都采用不同的形式

    <p:dataTable value="#{bean.list}" var="row" paginator="true" id="dataList#{formId}"
                 paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                 rowsPerPageTemplate="#{bean.tablePaginatorSizes}" rows="#{bean.tableDefaultPaginatorSize}"
                 emptyMessage="#{lang.label_no_records_found}"
                 selectionMode="single" rowKey="#{row.id}" widgetVar="packListTab">
   <p:column headerText="ID" sortBy="#{row.id.packageId}" filterBy="#{row.idStr}" filterMatchMode="contains"
                      width="150">
                <h:outputText value="#{row.idStr}"/>
            </p:column> 
</p:datatable>

PF 6.0版

编辑:

我将PF升级到6.2,出现了具有不同堆栈跟踪的NPE

java.lang.NullPointerException
    at org.primefaces.component.datatable.feature.SortFeature.decode(SortFeature.java:80)
    at org.primefaces.component.datatable.DataTableRenderer.decode(DataTableRenderer.java:71)
    at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:478)
    at org.primefaces.component.api.UIData.processDecodes(UIData.java:296)
    at org.apache.myfaces.context.servlet.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:775)
    at org.apache.myfaces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:213)
    at org.primefaces.component.api.UIData.visitTree(UIData.java:850)
    at javax.faces.component.UIForm.visitTree(UIForm.java:345)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1044)
    at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1191)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1044)
    at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1191)

debug result

这很奇怪,客户来自列之外的另一种形式(最后一种)。

1 个答案:

答案 0 :(得分:1)

NPE确实似乎是Primefaces tracked by issue 2059中的一个错误,其中可空对象引用上缺少null检查。升级到Primefaces 6.1应该可以解决此NPE。

通过使用Primefaces 6.0源代码检查Eclipse Java StackTrace console中的StackTrace,并将DataTable.findColumnInGroup(...)的方法实现与Primefaces 6.1源代码中的方法实现进行比较,发现了这一点。后者包含null检查:

public UIColumn findColumnInGroup(String clientId, ColumnGroup group) {
    if(group == null) {
        return null;
    }

    FacesContext context = this.getFacesContext();

    for(UIComponent row : group.getChildren()) {
    // ...
    }
}

Blaming the change in source tree向我指出了上面提到的跟踪问题。