如果它变为无效,如何自动重置h:selectOneMenu的选定值?

时间:2014-12-23 20:38:50

标签: ajax jsf selectonemenu

  • 选择值" A"从pulldown1开始,pulldown2将填充项目" A1"," A2"," A3"等
  • 选择值" A1"来自pulldown2
  • 选择价值" B"从pulldown1开始,pulldown2将填充项目" B1"," B2"," B3"等等(虽然它看起来没有任何东西被选中,' A1'实际上仍然存在,因为当我......)
  • 选择值" A"从pulldown1再次,pulldown2重新填充" A1" !

如果当前选择无效,有没有办法自动将selectOneMenu的值设置为null?

<h:panelGroup id="locationInformationPanel">

<h:selectOneMenu id="pulldown1">
    <f:ajax listener="#{LocationSelector.siteNameChangeListener}"
            render="locationInformationPanel" execute="@this"/>
    <f:selectItem itemLabel="" itemValue="" noSelectionOption="true"/>
    <f:selectItems  value="#{LocationSelector.siteNames}"/>
</h:selectOneMenu>

<h:selectOneMenu id="pulldown2">
    <f:ajax listener="#{LocationSelector.buildingChangeListener}"
            render="locationInformationPanel" execute="@this"/>
    <f:selectItem itemLabel="" itemValue="" noSelectionOption="true"/>
    <f:selectItems  value="#{LocationSelector.buildings}"/>
</h:selectOneMenu>

</h:panelGroup>
public void siteNameChangeListener(AjaxBehaviorEvent e) {
   String selectedSiteName = getSelectionsFromEvent(e);
    updateBuildings(selectedSiteName);
}

注意:这些菜单没有任何&#34;值&#34;绑定到它们的字段但是,即使我绑定它们,它仍然会发生。绑定字段最终保存第一个无效值

1 个答案:

答案 0 :(得分:0)

我不确定这是不是&#34;对&#34;方式,但我添加了'pulldown2&#39;到pulldown1中的ajax标签的execute属性,它起作用了:

<h:selectOneMenu id="pulldown1">
    <f:ajax listener="#{LocationSelector.siteNameChangeListener}"
            render="locationInformationPanel" execute="@this pulldown2"/>

有关此方法的任何反馈意见?