问题描述
我试图使用带有自定义布局的selectOneRadio所示,这里的最后一个例子:的
I'm trying to use the selectOneRadio with custom layout as shown in the last example here: http://www.primefaces.org/showcase/ui/selectOneRadio.jsf
<p:selectOneRadio id="customRadio" layout="custom"
value="#{myBB.queryType}">
<f:selectItem itemValue="A"/>
<f:selectItem itemValue="B"/>
<f:selectItem itemValue="C"/>
<p:ajax process="@this" update="queryOptions"/>
</p:selectOneRadio>
<p:panelGrid columns="3" id="queryOptions">
<p:radioButton id="option1" for="customRadio" itemIndex="0"/>
<p:radioButton id="option2" for="customRadio" itemIndex="1"/>
<p:radioButton id="option3" for="customRadio" itemIndex="2"/>
<p:inputText value="#{myBB.queryType}"/>
</p:panelGrid>
我需要自定义布局,因为在其他组件的 queryOptions
panelGrid中,我需要根据选择的单选按钮来更新。在backingbean的值是否正确更新了一下,但我得到这个奇怪的异常:
I need custom layout, because there are other components in the queryOptions
panelGrid which I need to update based on the selected radioButton. The value in the backingbean is correctly updated on click, but I get this strange exception:
java.lang.NullPointerException
at org.primefaces.component.radiobutton.RadioButtonRenderer.encodeMarkup(RadioButtonRenderer.java:48)
at org.primefaces.component.radiobutton.RadioButtonRenderer.encodeEnd(RadioButtonRenderer.java:38)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1903)
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeDynamicBody(PanelGridRenderer.java:92)
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeBody(PanelGridRenderer.java:60)
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:49)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1903)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:559)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1729)
什么引起的呢?
What could be causing it?
我使用Primefaces 4.0和Mojarra 2.2.4
I'm using Primefaces 4.0 and Mojarra 2.2.4
推荐答案
我可以看到你把号码:单选
阿贾克斯更新panelGrid中在
As I can see that you are putting the p:radioButton
inside the ajax update panelGrid.
此方法要更新的号码:单选
不更新customeRadio('老板')
This way you are updating the p:radioButton
without updating the customeRadio ('owner').
您可以通过两种方式解决这个问题:
You can solve this by two ways:
第一:的更新也将号码:selectOneRadio相关的单选按钮
First: update also the p:selectOneRadio related to the radioButtons
<p:ajax process="@this" update="queryOptions @this"/>
或的
OR
二:的把更新的容器外的单选按钮
Second: put the radioButtons outside the updated container.
<p:radioButton id="option1" for="customRadio" itemIndex="0"/>
<p:radioButton id="option2" for="customRadio" itemIndex="1"/>
<p:radioButton id="option3" for="customRadio" itemIndex="2"/>
<p:panelGrid columns="3" id="queryOptions">
</p:panelGrid>
希望这有助于。
Hope this helps.
这篇关于自定义使用AJAX事件时异常selectOneRadio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!