Hide and show components depending on h:selectOneRadio value

843 views Asked by At

I have a page with a p:selectOneRadio and I want to show one datatable depending on the chosen value of the radio selection. I have the error:

GRAVE: javax.el.MethodNotFoundException: .......changeListenerMethod(javax.faces.event.AjaxBehaviourEvent)

My code is the following:

<p:selectOneRadio value="#{analysisOrderForm.selectedOrderDomain}">
     <f:selectItem itemLabel="choice1" itemValue="choice1"></f:selectItem>         
     <f:selectItem itemLabel="choice2" itemValue="choice2"></f:selectItem>
     <p:ajax event="change" listener="#{analysisOrderForm.changeListenerMethod}"/>
 </p:selectOneRadio>
 <h:PanelGroup>
    <p:dataTable rendered="#{analysisOrderForm.selectedOrderDomain == 'choice1'}">....</p:dataTable>
    <p:dataTable rendered="#{analysisOrderForm.selectedOrderDomain == 'choice2'}">....</p:dataTable>
 </h:PanelGroup>

The code of my 'changeListenerMethod method' is just:

 public void changeListenerMethod(ValueChangeEvent e){
      setSelectedOrderDomain(e.getValue().toString());
 }

What is correct and what is wrong in my code?

1

There are 1 answers

0
Mathieu Castets On

When using

<p:ajax event="change" listener="#{analysisOrderForm.changeListenerMethod}"/>

JSF will look for a method in your analysisOrderForm bean which has the following signature: public void changeListenerMethod(AjaxBehaviourEvent e). So you just need to replace ValueChangeEvent by AjaxBehaviourEvent.


Notes:

  • Another alternative approach is to write a method that doesn't take any arguments such as public void changeListenerMethod() and references it in your listener with listener="#{analysisOrderForm.changeListenerMethod()}
  • Event change is not the right event in your case. p:selectOneRadio event should be click (besides, that's the default event value). See also https://stackoverflow.com/a/21292158/2118909