NeplatnyUdaj
NeplatnyUdaj

Reputation: 6242

Exception when using ajax event on custom 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>

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?

I'm using Primefaces 4.0 and Mojarra 2.2.4

Upvotes: 2

Views: 1661

Answers (1)

Hatem Alimam
Hatem Alimam

Reputation: 10048

As I can see that you are putting the p:radioButton inside the ajax update panelGrid.

This way you are updating the p:radioButton without updating the customeRadio ('owner').

You can solve this by two ways:

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.

Upvotes: 6

Related Questions