views:

1733

answers:

1

I'm attempting to put a few drop down menus inside of an a4j:repeat. The values for the second drop down are dependent on the value selected in the first. Below is the code I am attempting to use, but it passes a blank parameter:

<a4j:repeat id="localRepeat" var="local" value="#{InstanceController.instance.locations}" rowKeyVar="row">
                    <h:panelGrid columns="2">
                        <h:outputLabel value="Theater:" />
                        <h:selectOneMenu  id="theater" converter="#{TheaterConverter}" value="#{local.theater}">
                            <f:selectItems id="theaters" value="#{InstanceController.allTheaters}" />
                            <a4j:support event="onchange" action="#{InstanceController.getAllCountriesInTheater}" reRender="country" >
                                <f:param name="theater" value="#{local.theater.id}"/>
                            </a4j:support>
                        </h:selectOneMenu>

                        <h:outputLabel value="Country:" />
                        <h:selectOneMenu immediate="true" id="country" converter="#{CountryConverter}" value="#{local.country}">
                            <f:selectItems  value="#{InstanceController.allCountriesInTheater}" />
                            <a4j:support event="onchange" reRender="state" />
                        </h:selectOneMenu>

                    </h:panelGrid>
                    <rich:spacer height="10px" />
                </a4j:repeat>

If I change the f:param to send "1" instead of "#{local.theater.id}" it works as expected.

Is there a way to get the selected value of the first drop down and send it as a parameter?

+2  A: 

This reason this doesn't work is that when the f:param tag is rendered, the current value of local.theater.id is already assigned to the parameter. So the theater param will contain the id of the theater that was selected when the page was rendered - probably null because no theater has been selected yet.

What you are trying to do is far more easy: Just remove the f:param and use the property directly. When the a4j:support tag triggers because the selectbox value was changed, jsf will validate your form tags and assign the appropriate model values. So, when the getAllCountriesInTheater action gets executed, the local.theater property will already contain the selected theater.

Depending on how your backing beans are designed, you will probably need a parameter to identify the location for which the selectbox was changed, so the getAllCountriesInTheater action will know in which of the locations to look for the selected theater.

FRotthowe