PrimeFaces PickList与OmniFaces validateAll导致NullPointerException

问题描述 投票:4回答:2

我真正想要的是两个用PrimeFaces <p:pickList>组件验证的OmniFaces' <o:validateAll>s。注意,使用<o:validateAll>验证pickList有一个问题,可以在OmniFaces问题跟踪器中解决为described in issue 488

所以我的要求的一个非常简单的例子如下:

<h:form id="form1">
  <p:messages id="messages">
    <p:autoUpdate/>
  </p:messages>

  <p:pickList id="pick1" value="#{dummy.dualListModel}"
              var="item" itemLabel="#{item}" itemValue="#{item}">
    <p:ajax event="transfer"/>
  </p:pickList>

  <p:pickList id="pick2" value="#{dummy.dualListModel2}"
              var="item" itemLabel="#{item}" itemValue="#{item}">
    <p:ajax event="transfer"/>
  </p:pickList>

  <o:validateAll id="validPicks" components="pick1 pick2"
                 message="all values required!" />

  <h:commandButton id="done" value="Done" action="#{dummy.action1}"/>
</h:form>

<h:form id="theOtherForm">
  <h:commandButton id="otherFormAction" value="Action in other form"
                   action="#{dummy.action2}"/>
</h:form>

后面的虚拟后备bean只为两个dualListModel属性和不执行任何操作的操作方法提供getter / setter。

当我运行此代码并保留至少一个pickList为空时,提交Done按钮会导致验证失败,因为例外。但是,在验证失败后单击其他表单中的按钮会导致NullPointerException中的PickListRenderer。这是StackTrace:

Caused by:java.lang.NullPointerException
    at org.primefaces.component.picklist.PickListRenderer.encodeMarkup(PickListRenderer.java:92)
    at org.primefaces.component.picklist.PickListRenderer.encodeEnd(PickListRenderer.java:59)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:920)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:890)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:456)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:134)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    at org.omnifaces.viewhandler.OmniViewHandler.renderView(OmniViewHandler.java:119)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    [...]

我使用OmniFaces 2.7和PrimeFaces 6.2。

请注意,我正在使用覆盖getConvertedValue()的PickList的自定义渲染器,如上面的链接问题中所述。但是,这不会以任何方式改变渲染器的行为,从而影响此错误。它只是让<o:validateAll>认识到pickList是空的。

这对我来说似乎是个错误,但我不确定它是否是OmniFaces或PrimeFaces中的错误。有人有任何想法吗?

解决方法

作为一种解决方法,可以将required="true"属性添加到所有pickLists。

更新

PrimeFaces 7.0存在同样的问题(只是行号略有不同)。

此外,我通过上述代码和PrimeFaces 7.0生成了另一个NPE,当通过“完成”提交空的选项列表,然后将其中一个选项列表中的项目转移到目标列表时。

另一个例外发生在这里:

Caused by:java.lang.NullPointerException
    at org.primefaces.component.picklist.PickList.validateValue(PickList.java:140)
    at javax.faces.component.UIInput.validate(UIInput.java:982)
    at org.primefaces.component.picklist.PickList.validate(PickList.java:181)
    at javax.faces.component.UIInput.executeValidate(UIInput.java:1248)
    at javax.faces.component.UIInput.processValidators(UIInput.java:712)
    at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:575)
    at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1689)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
    at javax.faces.component.UIForm.visitTree(UIForm.java:371)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
    at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:403)
    at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:266)
    at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:63)
    at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:219)
    at org.omnifaces.context.OmniPartialViewContext.processPartial(OmniPartialViewContext.java:124)
    at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1193)
    at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)

corresponding code中,通过oldModel初始化的getValue()的值是null

jsf primefaces omnifaces
2个回答
2
投票

问题经过验证并在GitHub上报告:https://github.com/primefaces/primefaces/issues/4756

我提交了一个修复程序,希望将其包含在PF 7.0.2和PF 7.1中

https://github.com/primefaces/primefaces/pull/4759


1
投票

正如Melloware所写,这个问题被报道为PrimeFaces issue #4756。事实证明,问题只存在于Mojarra(使用2.2.17,2.2.18,2.2.19和2.3.9测试)而不是MyFaces。所以另一个问题是创建:Mojarra #4398

© www.soinside.com 2019 - 2024. All rights reserved.