0

在selectOneMenu中,當對f:validator,f:屬性進行驗證失敗時,valueChangeListener沒有被調用,我也試過immediate =「true」,但它沒有解決。 任何幫助將不勝感激。謝謝。 下面的代碼片段:當輸入驗證失敗時,不會調用valueChangeListener

<p:selectOneMenu id="firstinputselectone" rendered="#{!dynamicUIPreEnrollmentAction.singleProfile}" 
         valueChangeListener="#{dynamicUIPreEnrollmentAction.showLayoutPreview}" 
         styleClass="#{extraFieldDTO.isReadOnly eq '1' ?'disabledInputFieldSelectItem' :'enabledInputFieldSelectItem'}" 
         disabled="#{extraFieldDTO.isReadOnly eq '1'}" 
         value="#{extraFieldDTO.stringFieldValue}"> 
    <f:selectItem itemLabel="#{msg.DROP_SELECTONE}" 
     id="selectItem_24" /> 

    <f:selectItems 
     value="#{dropDownParserAction.getGenericLinkedKeyValueListMap(null,extraFieldDTO.dropDownSearchValue,extraFieldDTO.dropDownType,extraFieldDTO.firstLinkedDropDownType)}" 
     id="selectItems_24655" /> 
    <p:ajax event="change" id="ajax_2" update="@form" /> 
    <f:validator validatorId="dynamicUIValidator" /> 
    <f:attribute name="DYNAMICUIDATAOBJECT" value="#{extraFieldDTO}" /> 
</p:selectOneMenu> 

        </h:panelGroup> 
           </p:fieldset> 
           <p:spacer width="50" /> 
           <p:fieldset legend="#{msg.LBL_BACKCARD}" toggleable="false" 
            style="width:400px;height:400px;background-color:#e6e6e6"> 
            <h:panelGroup> 
             <br clear="none" /> 
             <br clear="none" /> 
             <br clear="none" /> 
             <br clear="none" /> 
             <p:spacer height="40" /> 
             <h:graphicImage id="layout_present_idar590" rendered="#{dynamicUIPreEnrollmentAction.backProfileLayout ne null}" 
              value="data:image/jpg;base64,#{dynamicUIPreEnrollmentAction.backProfileLayout}" /> 

            </h:panelGroup> 
           </p:fieldset> 
          </h:panelGrid> 
         </div> 
        </p:outputPanel> 
+0

如果驗證失敗,那麼就只是一個新的價值沒辦法,所以這是合乎邏輯的事情不會不會被調用。你的功能需求是什麼?即你試圖用價值變化監聽者來解決什麼問題?如果你從不使用event.getOldValue(),那絕對是這個工作的錯誤工具。如果您詳細說明所需的工作,那麼我們可以提出實現這一目標的正確方法。 – BalusC

+0

是你是正確的@BalusC,但我的要求是,根據選擇我正在渲染一些佈局(與一對一關係)與選定的下拉列表,如果我們選擇selectOneMenu不應該呈現以前的佈局。但由於驗證失敗,我無法重置佈局。無論如何,我通過在佈局面板中使用rendered =「!facesContext.validationFailed」來解決該問題。 – curiousManish

回答

0
Thanks, I got the workaround for this by using rendered="!facesContext.validationFailed" in the layouts panel which was not supposed to be rendered when validation fails. 
Here is the code snippet: 



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://xmlns.jcp.org/jsf/html" 
    xmlns:p="http://primefaces.org/ui"> 

      <p:tabView 
       rendered="#{extraFieldDTO.fieldType.equals('IDENTITY_CREDENTIAL')}"> 
       <p:tab title="#{msg.LBL_IDENTITY_CREDENTIAL}"> 
        <br clear="none" /> 
        <br clear="none" /> 
        <p:outputPanel autoUpdate="true"> 
        <h:panelGroup 
         rendered="#{extraFieldDTO.fieldType.equals('IDENTITY_CREDENTIAL')}"> 
         <h:panelGrid columns="2" style="width:100%;" 
          columnClasses="padding widthDyna,row1-padding"> 
        <h:panelGroup id="panelGroup_31D0"> 
         <p:outputLabel value="#{extraFieldDTO.displayText}" /> 
         <h:outputText id="idar563" styleClass="red" value="*" rendered="#{extraFieldDTO.isRequiredField eq '1'}" /> 
         <p:selectOneMenu id="firstinputselectone" rendered="#{!dynamicUIPreEnrollmentAction.singleProfile}" immediate="true" 
          valueChangeListener="#{dynamicUIPreEnrollmentAction.showLayoutPreview}" 
          styleClass="#{extraFieldDTO.isReadOnly eq '1' ?'disabledInputFieldSelectItem' :'enabledInputFieldSelectItem'}" 
          disabled="#{extraFieldDTO.isReadOnly eq '1'}" 
          value="#{extraFieldDTO.stringFieldValue}"> 
          <f:selectItem itemLabel="#{msg.DROP_SELECTONE}" 
           id="selectItem_24" /> 

          <f:selectItems 
           value="#{dropDownParserAction.getGenericLinkedKeyValueListMap(null,extraFieldDTO.dropDownSearchValue,extraFieldDTO.dropDownType,extraFieldDTO.firstLinkedDropDownType)}" 
           id="selectItems_24655" /> 
          <p:ajax event="change" id="ajax_2" update="@form" immediate="true"/> 
          <f:validator validatorId="dynamicUIValidator" /> 
          <f:attribute name="DYNAMICUIDATAOBJECT" value="#{extraFieldDTO}" /> 
         </p:selectOneMenu> 

         <p:selectOneMenu id="firstinputselectone_SingleProfile" 
          rendered="#{dynamicUIPreEnrollmentAction.singleProfile}" 
          valueChangeListener="#{dynamicUIPreEnrollmentAction.showLayoutPreview}" 
          styleClass="#{extraFieldDTO.isReadOnly eq '1' ?'disabledInputFieldSelectItem' :'enabledInputFieldSelectItem'}" 
          disabled="#{extraFieldDTO.isReadOnly eq '1'}" 
          value="#{extraFieldDTO.stringFieldValue}"> 


          <f:selectItems 
           value="#{dropDownParserAction.getGenericLinkedKeyValueListMap(null,extraFieldDTO.dropDownSearchValue,extraFieldDTO.dropDownType,extraFieldDTO.firstLinkedDropDownType)}" 
           id="selectItems_24655_SingleProfile" /> 
          <f:validator validatorId="dynamicUIValidator" /> 
          <f:attribute name="DYNAMICUIDATAOBJECT" value="#{extraFieldDTO}" /> 
         </p:selectOneMenu> 
        </h:panelGroup> 
        <h:panelGroup style="width:40%"> 
           <h:outputText 
            value="#{msg.HELP_DYNA_FORM_EDIT_FIELDMGMT_HELP}:&nbsp;" 
            rendered="#{extraFieldDTO.helpText !=null}" /> 
           <h:outputText value="#{extraFieldDTO.displayText}" 
            rendered="#{extraFieldDTO.helpText !=null}" /> 
           <br clear="none" /> 
           <span class="garyText"> <h:outputText 
             value="#{extraFieldDTO.helpText}" 
             rendered="#{extraFieldDTO.helpText !=null}" /></span> 
           <br clear="none" /> 

          </h:panelGroup> 
         </h:panelGrid> 
         <br clear="none" /> 
         <p:message for="firstinputselectone" id="message_38" /> 
         <br clear="none" /> 
         <p:outputPanel autoUpdate="true" id="layout_Panel" rendered="#{not empty extraFieldDTO.stringFieldValue and !facesContext.validationFailed}"> 
          <div align="center"> 
           <h:panelGrid id="layout_present" columns="3" 
            rendered="#{(not empty extraFieldDTO.stringFieldValue) and ((dynamicUIPreEnrollmentAction.frontProfileLayout ne null) or (dynamicUIPreEnrollmentAction.backProfileLayout ne null))}"> 
            <p:fieldset legend="#{msg.LBL_FRONTCARD}" toggleable="false" 
             style="width:400px;height:400px;background-color:#e6e6e6"> 
             <h:panelGroup> 
              <br clear="none" /> 
              <p:spacer height="30" /> 
              <h:graphicImage id="layout_present_idar589" rendered="#{dynamicUIPreEnrollmentAction.frontProfileLayout ne null}" 
               value="data:image/jpg;base64,#{dynamicUIPreEnrollmentAction.frontProfileLayout}" /> 

             </h:panelGroup> 
            </p:fieldset> 
            <p:spacer width="50" /> 
            <p:fieldset legend="#{msg.LBL_BACKCARD}" toggleable="false" 
             style="width:400px;height:400px;background-color:#e6e6e6"> 
             <h:panelGroup> 
              <br clear="none" /> 
              <br clear="none" /> 
              <br clear="none" /> 
              <br clear="none" /> 
              <p:spacer height="40" /> 
              <h:graphicImage id="layout_present_idar590" rendered="#{dynamicUIPreEnrollmentAction.backProfileLayout ne null}" 
               value="data:image/jpg;base64,#{dynamicUIPreEnrollmentAction.backProfileLayout}" /> 

             </h:panelGroup> 
            </p:fieldset> 
           </h:panelGrid> 
          </div> 
         </p:outputPanel> 
        </h:panelGroup> 
        </p:outputPanel> 
       </p:tab> 
      </p:tabView> 


</ui:composition>