在从一个h选择值时:selectOneMenu下拉标记导致删除另一个下拉值的值

时间:2016-12-09 06:26:21

标签: jsf-2

我的jsf页面中有3个下拉列表。

  1. 到达区域
  2. 出发区
  3. 凭证类型
  4. 它在我的页面中以相同的顺序出现。

    如果我选择到达区域或出发区域的值,然后选择凭证区域的值,则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>
    

1 个答案:

答案 0 :(得分:1)

As Nurzhan pointed out as you have not attached any <f:ajax> tags to the first 2 <h:selectOneMenu> tags no ajax event is getting fired when the user changes his selection in those menues. That means the setters in your model don't get called. But on the third <h:selectOneMenu> you attached an <f:ajax> tag with a render attribute that references the id of a tag that contains all the menues (as i can presume). Therebye in the render response phase the getters of all components inside 'fplusAdd' are called and the menues are being set back to their inital vales. To fix that problem either add ajax tags to the first menues as well (so that the model gets updated with each userselection or simply reference them in the the ajax tag in the execute attribute as well, like:

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

Therebye the first two menues will also get processed (as well as anything else which is inside 'fplusAdd'), which means that the setters of the model are called. If you don't explicitly add an execute attribute the default value is @this, which means only the component itself is getting processed (the corresponding setters are called)