Samuel French
Samuel French

Reputation: 665

JSF selectOneMenu value changed event triggering help (Java Server Faces)

I want to trigger an Ajax event when the selected value of the selectOneMenu is changed.

The idea is to update the textArea based on the new value.

    <h:form id="selectForm">
        <h:graphicImage id="carImage">
        </h:graphicImage>
        <h:selectOneMenu id="carList" value="#{RequestBean.index}">
            <f:selectItems value="#{CarInfoBean.allCarNames}" itemLabel="#{CarInfoBean.carNumber}" />
            <f:ajax  render="carDescription"/>
        </h:selectOneMenu>
        <br/>

        <h:inputTextarea id="carDescription" value="#{RequestBean.infoString}" readonly="true" >
        </h:inputTextarea>
    </h:form>

The part I am confused on is how I trigger the event. Do I need a valueChangeListener in the select tag? Do I set something for the change attribute of the selectOneMenu, or can I specify the triggering event within the ajax tag somehow?

Thanks, Sam French

Upvotes: 0

Views: 1616

Answers (1)

Stefan
Stefan

Reputation: 271

An ajax-Listener should do the thing:

<h:selectOneMenu ...>
    ...
     <f:ajax event="change" execute="@this"  listener="#{CarInfoBean.foo()}" render="carDescription" />
</h:selectOneMenu>

(Note: you have to use the update attribute, since the render attribute does something different.)

Upvotes: 1

Related Questions