自定义使用AJAX事件时异常selectOneRadio自定义、异常、事件、selectOneRadio

2023-09-10 20:35:25 作者:Renaitre(复活)

我试图使用带有自定义布局的selectOneRadio所示,这里的最后一个例子:的 http://www.primefaces.org/showcase/ui/selectOneRadio.jsf

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.