Anish D
Anish D

Reputation: 21

<h:selectOneRadio> value not updated in bean

<h:form>
    <h:messages />
        <h:selectOneRadio value="#{bean.selectedValue}" id="selectId"
            layout="pageDirection">
            <f:selectItems value="#{bean.values}" var="value"
                itemLabel="#{value.text}" itemValue="{value}" />
        </h:selectOneRadio>
        <h:commandButton value="Press Me" >
            <f:ajax listener="#{bean.btn_action}" execute="@form"/>
        </h:commandButton>
</h:form>

Below are code details.

Issues. - When execute=@form is added to ajax tag, listener is not even called. - After execute-@form, listener is getting called however radio button selected value is not updated in backing bean. - When i debug getter is always called for selectedValue never the setter.

Any help will be appreciated. Thanks.

Upvotes: 2

Views: 4641

Answers (1)

BalusC
BalusC

Reputation: 1108722

Assuming that itemValue="{value}" is just a careless typo and that you never paid attention to the server logs, then this construct will silently fail if #{value} represents a non-standard type and you don't have a Converter for that type or didn't implement the type's equals() method properly.

First step would be adding render="@form" to <f:ajax>, so that <h:messages> get updated as well, so that you don't need to look into server logs for conversion/validation errors.

<f:ajax execute="@form" listener="#{bean.btn_action}" render="@form" />

Second step would be fixing the problem based on the shown conversion/validation error. Most likely you've a conversion error "null converter" or maybe you already have one, but you're getting a validation error "value is not valid" instead.

Both potential problems are answered in detail in the following answers:

Upvotes: 3

Related Questions