0

我正在尝试在 a4j:repeat 中放置一些下拉菜单。第二个下拉列表的值取决于第一个下拉列表中选择的值。下面是我尝试使用的代码,但它传递了一个空白参数:

<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>

如果我将 f:param 更改为发送“1”而不是“#{local.theater.id}”,它会按预期工作。

有没有办法获取第一个下拉列表的选定值并将其作为参数发送?

4

1 回答 1

2

这个不起作用的原因是当 f:param 标签被渲染时,local.theater.id 的当前值已经分配给参数。因此,剧院参数将包含在呈现页面时选择的剧院的 id - 可能为空,因为尚未选择剧院。

您要做的事情要简单得多:只需删除 f:param 并直接使用该属性。当 a4j:support 标记因选择框值更改而触发时,jsf 将验证您的表单标记并分配适当的模型值。因此,当执行 getAllCountriesInTheater 操作时,local.theater 属性将已经包含选定的剧院。

根据 backing beans 的设计方式,您可能需要一个参数来标识选择框更改的位置,因此 getAllCountriesInTheater 操作将知道在哪个位置查找所选剧院。

于 2009-11-06T13:05:12.713 回答