问题描述
我真正想要的是两个 PrimeFaces <p:pickList>
s已通过 OmniFaces的<o:validateAll>
组件进行了验证.请注意,使用<o:validateAll>
验证pickList存在问题,可以解决为问题中描述的 488 在OmniFaces问题跟踪器中.
What I actually want is two PrimeFaces <p:pickList>
s that get validated with OmniFaces' <o:validateAll>
component. Note, that validating a pickList with <o:validateAll>
has a problem, which can be solved as described in issue 488 in the OmniFaces issue tracker.
因此,我的要求的一个非常简单的示例如下所示:
So a very simple example of my requirement looks like this:
<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>
后面的 dummy 备用bean只是为两个dualListModel
属性和不做任何操作的动作方法提供了getter/setter方法.
The dummy backing-bean behind just provides getters/setters for the two dualListModel
properties and the action-methods that do nothing.
当我运行此代码并将至少一个pickList留为空白时,提交Done
-按钮会引发验证失败,例外.但是,在验证失败后单击另一种形式的按钮会导致PickListRenderer
中的NullPointerException
.这是StackTrace:
When I run this code and leave at least one pickList empty, submitting the Done
-button brings up a validation failure as excepted. However, clicking the button in the other form after the validation failed, leads to a NullPointerException
in the PickListRenderer
. Here is the 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.
Im using OmniFaces 2.7 and PrimeFaces 6.2.
请注意,我正在使用自定义渲染器作为PickList来覆盖getConvertedValue()
,如上面的链接问题所述.但是,这不会以任何会影响此错误的方式改变渲染器的行为.它只是使<o:validateAll>
识别pickList为空.
Please note, that I'm using a custom renderer for the PickList that overrides getConvertedValue()
, as described in the linked issue from above. However, this does not change behavior of the renderer in any way that should effect this bug. It just makes <o:validateAll>
recognize that the pickList is empty.
对我来说,这似乎是一个错误,但是我不确定这是OmniFaces还是PrimeFaces中的错误.有人知道吗?
This seems like a bug to me, but I'm not sure if it is a bug in OmniFaces or in PrimeFaces. Anyone got any idea?
作为一种解决方法,可以将required="true"
属性添加到所有pickList中.
As a workaround one could add the required="true"
attribute to all of the pickLists.
PrimeFaces 7.0存在相同的问题(只是行号略有不同).
The same problem exists with PrimeFaces 7.0 (just the line numbers differ a bit).
此外,当通过完成"将空选择列表汇总后,将其中一个选择列表中的项目转移到目标列表时,我用上述代码和PrimeFaces 7.0制作了另一个NPE.
In addition I produced another NPE with the above code and PrimeFaces 7.0, when sumbitting empty picklists via "done" and then transfering an item in one of the picklist to the target list.
另一个异常发生在这里:
The other exception occurs here:
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)
在相应代码,通过getValue()
初始化的oldModel
值为null
.
In the corresponding code, the value of oldModel
, which is initialized via getValue()
is null
.
推荐答案
如 Melloware 所述,该问题报告为 PrimeFaces问题#4756 .事实证明,该问题仅存在于Mojarra(经2.2.17、2.2.18、2.2.19和2.3.9测试),而MyFaces则不存在.因此,另一个问题产生了: Mojarra#4398 .
As Melloware wrote, the issue was reported as PrimeFaces issue #4756. It turned out, that the problem only exists with Mojarra (tested with 2.2.17, 2.2.18, 2.2.19 and 2.3.9) and not with MyFaces. So another issue was create: Mojarra #4398.
这篇关于PrimeFaces PickList与OmniFaces validateAll导致NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!