【问题标题】:On selecting value from one h:selectOneMenu drop down tag leads to removal of value of another drop down value从一个 h:selectOneMenu 下拉标签中选择值会导致删除另一个下拉值的值
【发布时间】:2016-12-09 06:26:20
【问题描述】:

我的 jsf 页面中有 3 个下拉菜单。

  1. 到达区
  2. 出发区
  3. 凭证类型

它在我的页面中以相同的顺序出现。

如果我为到达区或出发区选择一个值,然后我为凭证区选择一个值,则 1 和 2 中的值将更改为默认值。

这是我的代码。

<h:column rendered="#{(fplusRulesHandler.fplusRulesBean.searchBased eq 'DEP ZONE/ARR AIRPORT') or (fplusRulesHandler.fplusRulesBean.searchBased eq 'DEP ZONE/ARR ZONE')}">
    <h:outputText styleClass="head-table" value="Departing Zone"></h:outputText>
    <h:outputText styleClass="mandatory" value="*" />
</h:column>
<h:column rendered="#{(fplusRulesHandler.fplusRulesBean.searchBased eq 'DEP ZONE/ARR AIRPORT') or (fplusRulesHandler.fplusRulesBean.searchBased eq 'DEP ZONE/ARR ZONE')}">
    <h:selectOneMenu value="#{fplusRulesHandler.fplusRulesBean.fpuFlightRules.bpmAppFltIdentity.depZone}">
        <f:selectItems value="#{fplusRulesHandler.fplusRulesBean.arrDepZoneList}"></f:selectItems>
    </h:selectOneMenu>
</h:column>

<h:column rendered="#{(fplusRulesHandler.fplusRulesBean.searchBased eq 'ARR ZONE/DEP AIRPORT') or (fplusRulesHandler.fplusRulesBean.searchBased eq 'DEP ZONE/ARR ZONE')}">
    <h:outputText styleClass="head-table" value="Arrival Zone"></h:outputText>
    <h:outputText styleClass="mandatory" value="*" />
</h:column>
<h:column rendered="#{(fplusRulesHandler.fplusRulesBean.searchBased eq 'ARR ZONE/DEP AIRPORT') or (fplusRulesHandler.fplusRulesBean.searchBased eq 'DEP ZONE/ARR ZONE')}">
    <h:selectOneMenu value="#{fplusRulesHandler.fplusRulesBean.fpuFlightRules.bpmAppFltIdentity.arrZone}">
        <f:selectItems value="#{fplusRulesHandler.fplusRulesBean.arrDepZoneList}"></f:selectItems>
    </h:selectOneMenu>
</h:column>

<h:column>
    <h:outputLabel styleClass="head-table" value="Voucher Type"></h:outputLabel>
</h:column>
<h:column>
    <h:selectOneMenu value="#{fplusRulesHandler.fplusRulesBean.fpuFlightRules.voucherType}">
        <f:selectItem itemLabel="LONG HAUL UPGRADE" itemValue="LONG HUAL UPGRADE" />
        <f:selectItem itemLabel="EUROPE UPGRADE" itemValue="EUROPE UPGRADE" />
        <f:ajax event="change" render="fplusAdd"></f:ajax>
    </h:selectOneMenu>
</h:column>
<h:column rendered="#{fplusRulesHandler.fplusRulesBean.fpuFlightRules.voucherType == 'EUROPE UPGRADE'}">
    <h:outputLabel styleClass="head-table" value="#{message['FplusRules.AddRules.Label.RedemptionPointDiscount']}"></h:outputLabel>
</h:column>

<h:column rendered="#{fplusRulesHandler.fplusRulesBean.fpuFlightRules.voucherType == 'EUROPE UPGRADE'}">
    <h:inputText id="redemptionDiscount" value="#{fplusRulesHandler.fplusRulesBean.fpuFlightRules.redemptionPointsDisc}" validatorMessage="#{errorMessage['redemptionPointDiscountPositive']}"
converterMessage="#{errorMessage['redemptionPointDiscountPositive']}">
        <f:convertNumber integerOnly="true"></f:convertNumber>
        <f:validateLongRange minimum="0" />
    </h:inputText>
    <h:message for="redemptionDiscount" errorStyle="padding-left:10px;color :red" />
</h:column>

【问题讨论】:

  • 什么是 fplusAdd?
  • fplusAdd 是 panelGrid Id
  • 您是否尝试为所有 设置 ?似乎 selectOneMenus 被彼此重置 - 当您选择某个值时,其中的数据不会自动发送到服务器。

标签: jsf-2


【解决方案1】:

正如 Nurzhan 指出的那样,由于您没有将任何 &lt;f:ajax&gt; 标签附加到前 2 个 &lt;h:selectOneMenu&gt; 标签,因此当用户在这些菜单中更改其选择时,不会触发 ajax 事件。这意味着模型中的设置器不会被调用。 但是在第三个&lt;h:selectOneMenu&gt; 上,您附加了一个带有渲染属性的&lt;f:ajax&gt; 标记,该属性引用了包含所有菜单的标记的ID(我可以假设)。因此,在渲染响应阶段,“fplusAdd”中所有组件的 getter 都被调用,并且菜单被设置回它们的初始值。 要解决这个问题,要么将 ajax 标记添加到第一个菜单(以便模型随着每次用户选择而更新,或者也只需在 execute 属性 的 ajax 标记中引用它们,例如:

 <h:selectOneMenu value="#{fplusRulesHandler.fplusRulesBean.fpuFlightRules.voucherType}">
        <f:selectItem itemLabel="LONG HAUL UPGRADE" itemValue="LONG HUAL UPGRADE" />
        <f:selectItem itemLabel="EUROPE UPGRADE" itemValue="EUROPE UPGRADE" />
        <f:ajax event="change" execute="fplusAdd" render="fplusAdd"></f:ajax>
 </h:selectOneMenu>

因此,前两个菜单也将被处理(以及“fplusAdd”内的任何其他内容),这意味着模型的设置器被调用。如果你没有显式添加执行属性,默认值为@this,这意味着只有组件本身被处理(调用相应的setter)

【讨论】:

    猜你喜欢
    • 2014-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多