Performing a Bean Backup Action on p: selectOneRadio

I am using a radio component on which, when I select an element, I want to do a bean backing action (not go to the results page, but do some actions and then refresh the current page via Ajax). The problem is I can't get the background action bean to do the execution

<h:form id="one-radio">
    <p:selectOneRadio layout="grid" 
                    valueChangeListener="#{myBean.selectRadioItem}" >
        <p:ajax process="@this" update="@form" />
        <f:selectItems value="#{myBean.radioOptions}" var="radio"
            itemLabel="#{radio.name}" itemValue="#{radio.id}" >
        </f:selectItems>
    </p:selectOneRadio>
</h:form>

      

and the bean backing method ...

public void selectRadioItem(ValueChangeEvent event) {
    String[] selectedItems = (String[]) event.getNewValue();
    //more...
}

      

Is there something wrong with the code I'm missing? I used the same structure to select many checkboxes that work ...

+3


source to share


1 answer


Rodrigo, there is a difference between valueChangeListener and simple method call via ajax.

Check out this answer from BalusC about the difference between valueChangeListener

and<f:ajax>

To solve your problem, you can use the property listener

<p:ajax>

.

OneRadio component is used to accept only one value, if you want to select a list of values ​​use SelectOneMenu



Try the following:

<p:selectOneRadio layout="grid" value="#{myBean.radioValue}">
    <p:ajax process="@this" update="@form" listener="#{myBean.selectRadioItem}"/>
    <f:selectItems value="#{myBean.radioOptions}" var="radio"
        itemLabel="#{radio.name}" itemValue="#{radio.id}" >
    </f:selectItems>
</p:selectOneRadio>

      

In the backbean, you can remove the event parameter because the OneRadio component value is now a property that I named radioValue

String radioValue;
...
public void selectRadioItem() {
    String selectedItem = this.radioValue; 
//more...
}

      

+3


source







All Articles