当前位置: 首页 > 知识库问答 >
问题:

Primefaces:AccordionPanel内的DataTable抛出NullPointerException

宇文迪
2023-03-14

我有一个PrimefaceDataTable内的一个手风琴面板与动态标签数。可以通过单击列标题按每个列对DataTable进行排序。DataTable在更新行时在Primeface的DataTable类中抛出NullPointerExcture。只有在之前对表进行排序后才会发生错误。我已经在手风琴外面测试了同样的表,它没有显示错误。

我做错了什么?

我的xhtml:

<ui:define name="content">
    <h:form id="contentForm">

      <p:accordionPanel id="wearDataAccordion" value="#{wearDataBean.wearDataTypes}" var="type" multiple="true">
        <p:tab title="#{wearDataBean.getAggregateTypeLabel(type)}">

          <p:dataTable width="100%" var="wearData" value="#{wearDataBean.getWearData(type)}" sortBy="#{wearData.aggregate.sequence}" sortOrder="ASCENDING" 
                       scrollable="false" rowStyleClass="" styleClass="" emptyMessage="#{messages['lbl.no.data']}">

            <p:column headerText="#{messages['lbl.weardata.label']}" sortBy="#{wearData.aggregate.sequence}" width="15%">
              <p:outputLabel value="#{wearData.label}"/>
            </p:column>

            <p:column styleClass="column-numerical-right" headerText="#{messages['lbl.weardata.value']}" 
                                              sortBy="#{wearDataBean.getValue(wearData)}" width="5%">
              <p:outputLabel value="#{wearDataBean.getValue(wearData)}" style="float:right"/>
            </p:column>

            <p:column headerText="#{messages['lbl.weardata.unit']}" sortBy="#{wearData.unitId}" width="10%">
              <p:outputLabel value="#{wearDataBean.getUnitLabel(wearData.unitId)}"/>
            </p:column>

            <p:column headerText="#{messages['lbl.weardata.lastUpdate']}" sortBy="#{wearData.lastUpdate}" width="20%">
              <p:outputLabel value="#{wearData.lastUpdate}">
                <f:convertDateTime dateStyle="medium" timeStyle="medium" type="both" timeZone="#{localeData.timeZoneId}"/>
              </p:outputLabel>
            </p:column>  

            <p:column styleClass="column-button-icon" headerText="#{messages['lbl.dest.actions']}" width="7%">
              <eae:commandButton icon="/resources/images/ui_content_dest_service.svg" styleClass="" svgStyleClass="ui-svg-button-icon-only-svg-size" 
                                                title="#{messages['lbl.weardata.reset']}" action="#{wearDataBean.reset(wearData)}" global="false">
                <p:confirm header="#{messages['lbl.weardata.reset']}" message="#{messages['lbl.weardata.confirm.question']}" icon="ui-icon-alert" />
              </eae:commandButton>
            </p:column>

          </p:dataTable>

        </p:tab>
      </p:accordionPanel>


      <p:remoteCommand name="updateBean" actionListener="#{wearDataBean.updateData()}" global="false"/>
    </h:form>

    <p:socket onMessage="handleWearDataMessage" channel="#{messagePublisher.wearDataUpdateChannelName}"/>
    <script type="text/javascript">
      function handleWearDataMessage(data) {
        var jsonString = JSON.stringify(data);
        updateBean([{name: 'data', value: jsonString}]);
      }
    </script>

  </ui:define>

它抛出的异常是:

13:20:47,060 [SEVERE] [org.primefaces.application.exceptionhandler.PrimeExceptionHandler] (default task-7) null: java.lang.NullPointerException
   at org.primefaces.component.datatable.DataTable.findColumnInGroup(DataTable.java:903) [primefaces-5.1.14.jar:5.1.14]
   at org.primefaces.component.datatable.DataTable.findColumn(DataTable.java:894) [primefaces-5.1.14.jar:5.1.14]
   at org.primefaces.component.datatable.DataTable.getSortColumn(DataTable.java:1401) [primefaces-5.1.14.jar:5.1.14]
   at org.primefaces.component.datatable.feature.SortFeature.singleSort(SortFeature.java:136) [primefaces-5.1.14.jar:5.1.14]
   at org.primefaces.component.datatable.DataTableRenderer.preRender(DataTableRenderer.java:109) [primefaces-5.1.14.jar:5.1.14]
   at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:83) [primefaces-5.1.14.jar:5.1.14]
   at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
   at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
   at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
   at org.primefaces.component.accordionpanel.AccordionPanelRenderer.encodeTab(AccordionPanelRenderer.java:226) [primefaces-5.1.14.jar:5.1.14]
   at org.primefaces.component.accordionpanel.AccordionPanelRenderer.encodeTabs(AccordionPanelRenderer.java:171) [primefaces-5.1.14.jar:5.1.14]
   at org.primefaces.component.accordionpanel.AccordionPanelRenderer.encodeMarkup(AccordionPanelRenderer.java:103) [primefaces-5.1.14.jar:5.1.14]
   at org.primefaces.component.accordionpanel.AccordionPanelRenderer.encodeEnd(AccordionPanelRenderer.java:76) [primefaces-5.1.14.jar:5.1.14]
   at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
   at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
   at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:582) [jsf-impl-2.2.8-jbossorg-1.jar:]
   at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183) [jsf-impl-2.2.8-jbossorg-1.jar:]
   at org.primefaces.component.api.UITabPanel.visitTree(UITabPanel.java:948) [primefaces-5.1.14.jar:5.1.14]
   at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
   at javax.faces.component.UIForm.visitTree(UIForm.java:371) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
   at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
   at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
   at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
   at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:403) [jsf-impl-2.2.8-jbossorg-1.jar:]
   at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:322) [jsf-impl-2.2.8-jbossorg-1.jar:]
   at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60) [primefaces-5.1.14.jar:5.1.14]
   at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:219) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
   at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:1004) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
   at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
   at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:430) [jsf-impl-2.2.8-jbossorg-1.jar:]
   at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133) [jsf-impl-2.2.8-jbossorg-1.jar:]
   at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
   at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
   at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
   at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) [jsf-impl-2.2.8-jbossorg-1.jar:]
   at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.2.8-jbossorg-1.jar:]
   at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) [jsf-impl-2.2.8-jbossorg-1.jar:]
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
   at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.websockets.jsr.JsrWebSocketFilter.doFilter(JsrWebSocketFilter.java:129) [undertow-websockets-jsr-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
   at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
   at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.server.handlers.DisableCacheHandler.handleRequest(DisableCacheHandler.java:33) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:63) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
   at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
   at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:247) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:76) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:166) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.server.Connectors.executeRootHandler(Connectors.java:197) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
   at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:759) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_67]
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_67]
   at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_67]

来自后备bean的updateData()方法如下:

 /**
   * Refreshes the data within this bean 
   */
  public void updateData() {
    this.logger.debug("Ajax listener method for wearDataUpdate called!");

    // do update data
    boolean refreshAll = false;
    boolean refresh    = false;
    UpdateEvent<Integer> updateEvent = this.extractRequestData(new TypeToken<UpdateEvent<Integer>>() { /* ignored */ }.getType(), "data");
    if (updateEvent.getType().equals(Type.CREATE)) {
      refresh |= this.addWearDataToDomainData(updateEvent.getData());
    } else if (updateEvent.getType().equals(Type.DELETE)) {
      refresh |= this.removeWearDataFromDomainData(updateEvent.getData());
    } else {
      refreshAll = true;
    }

    // delete old data if refresh all is set
    if (refreshAll) {
      this.wearDataListsByType = null;
    }

    // update table in view
    if (refresh || refreshAll) {
      Ajax.update("contentForm:wearDataAccordion");
    }
  }

PrimeFaces 5.1.14,全脸2.0,WildFly 8.2.0

共有2个答案

徐焱
2023-03-14

对于从accordionPanel选项卡中动态生成的数据表的排序,我也遇到了同样的问题,widgetVar解决方案没有解决我的问题。

使排序工作正常的解决方案是包含一个p:columnGroup(除了使事情正常工作之外,没有什么用处)

<p:columnGroup type="header">
    <p:row>
        <p:column headerText="Column 1">...</p:column>
        ...
    </p:row>
</p:columnGroup>
澹台聪
2023-03-14

解决方案是在数据表中使用widgetVar=“data”。是Javascript识别此ID所必需的。

<p:dataTable width="100%" var="wearData" value="#{wearDataBean.getWearData(type)}" sortBy="#{wearData.aggregate.sequence}" sortOrder="ASCENDING" 
                   scrollable="false" rowStyleClass="" styleClass="" emptyMessage="#{messages['lbl.no.data']}" widgetVar="data">

简介PrimeFaces widgetVar

 类似资料:
  • JSF为开发人员提供了强大的功能来定义他们自己的自定义组件,可用于呈现自定义内容。 定义自定义组件 在JSF中定义自定义组件的过程分为两步。 步 描述 1a 创建资源文件夹。 使用复合命名空间在resources文件夹中创建xhtml文件。 1b 使用复合标签composite:interface, composite:attribute和composite:implementation,来定义复

  • JSF提供了一个名为DataTable的丰富控件来呈现和格式化html表。 DataTable可以迭代一个集合或值数组来显示数据。 DataTable提供了以简单方式修改其数据的属性。 HTML标头 <html xmlns = "http://www.w3.org/1999/xhtml" xmlns:h = "http://java.sun.com/jsf/html"> </h

  • 我们在AWS上运行h2o,在GBM algo上用14GB CSV数据集训练一个模型,它达到36%,然后失败,出现错误: “Java堆空间”,由Java.lang.OutOfMemoryError引起:Java堆空间 更新: 因此,我们将java选项-XMX设置为14G,并将其增加到25G,从而允许它继续运行。

  • 我目前有一个datatable由于某种原因不能放入div,有没有人知道如何“挤压”它,这样它就可以很好地放入我的div中&不需要滚动 代码:

  • 我有以下2个代码片段,我想知道是什么使java编译器(在Eclipse与Java7)显示错误的第二个片段,为什么不是第一个。 以下是代码片段: 片段1 片段2 在eclipse中,snippet1显示为finally块添加'SuppressWarning',但在snippet2中,它显示为catch块中的throw语句添加'throws或try catch'块。 我详细研究了以下问题,但没有提供任

  • 以下代码运行良好: 但是,当我使用orElseThrow从可选: 两者都抛出了一个RuntimeException,有什么想法为什么带有可选的方法不起作用吗? 更新:我的构建基础设施,我尝试用IntelliJ和Maven编译它: