2014-04-16 2 views
0

다음 대화 상자가 있습니다. 대화 상자에 포커스가있을 때 비밀번호 필드 포커스가 설정되지만 처음로드 될 때만 작동합니다. 비밀번호 필드 포커스를 설정할 때 암호가 일치하지 않습니다 (즉, 확인 버튼을 클릭하고 SSJS를 실행 한 후).대화 상자 (확장 라이브러리 대화 상자)에서 유효성 검사 후 필드 포커스 설정

<xe:dialog id="dialogConfirmPassword" title="Confirm Your Password"> 
    <xe:dialogContent id="dialogConfirmPasswordContent"> 
     <xp:messages id="messagesConfirmPassword" layout="table" /> 

     <xp:table style="width:100%" id="tableConfirmPassword"> 
      <xp:tr> 
       <xp:td> 
        <xp:label value="Password" id="lblPassword" 
         for="confirmPassword" /> 
       </xp:td> 
       <xp:td> 
        <xp:inputText id="confirmPassword" 
         password="true"> 
             </xp:inputText> 
       </xp:td> 
      </xp:tr> 
     </xp:table> 
    </xe:dialogContent> 

    <xe:dialogButtonBar id="dialogButtonBarConfirmPassword"> 
     <xp:button value="OK" id="btnConfirmPasswordOk"> 
      <xp:eventHandler event="onclick" submit="true" 
       refreshMode="complete"> 
       <xp:this.action> 
        <xp:actionGroup> 
         <xp:executeScript> 
          <xp:this.script><![CDATA[#{javascript:try{ 

      var confirmPassword:String = getComponent("confirmPassword").getValueAsString(); 

      if (session.verifyPassword(confirmPassword, HTTPPassword)){ 

       /* RUNS NOTES AGENT */ 

       getComponent('dialogConfirmPassword').hide(); 

       return true; 

      } else { 

       facesContext.addMessage("messagesConfirmPassword", new javax.faces.application.FacesMessage("You have entered an incorrect password, please try again.")); 

       /* WANT TO SET FOCUS FOR PASSWORD FIELD */ 

       return false; 

      } 
     } catch (e) { 
      facesContext.addMessage("messagesConfirmPassword", new javax.faces.application.FacesMessage("ERROR! " + e.toString())) 
      return false; 
     }}]]></xp:this.script> 
         </xp:executeScript> 
        </xp:actionGroup> 
       </xp:this.action> 
      </xp:eventHandler> 
     </xp:button> 

    </xe:dialogButtonBar> 

    <xp:eventHandler event="onFocus" submit="false"> 
     <xe:this.script><![CDATA[dijit.byId("dialogConfirmPassword").focus();]]></xe:this.script> 
    </xp:eventHandler> 

</xe:dialog> 

facesContext.addMessage 또는 다른 방법을 설정 한 후 암호 필드 포커스를 설정할 수 있습니까?

업데이트 : 다음 출력 스크립트 일 :

 <xp:scriptBlock id="scriptBlockConfirmPassword"> 
     <xp:this.value><![CDATA[#{javascript: if(viewScope.PWDSuccess === null) { 
    return ""; 
}; 

var result = "dojo.byId(\"";  
result += getComponent("confirmPassword").getClientId(facesContext); 
result += "\").focus();"; 

return result;}]]></xp:this.value> 
    </xp:scriptBlock> 

답변

1

몇 포인터 :

  • getComponent("confirmPassword") 같은 구성 요소 후 이동하지만, 범위 변수에 구성 요소를 결합하지 마십시오, 더 나은 코드
  • 한다
  • SSJS에서 직접 클라이언트 JavaScript 액션을 실행할 수 없습니다 (지정한 곳)
  • XPag ES ID는 (여기 만 필수품)는 outputscript 아마

그래서 코드를 수정하여 문제 해결할 수

  • 클라이언트 측 ID와 다른 :

    <xp:inputText id="confirmPassword" password="true" value="#{viewScope.confirmPWD}"> 
    </xp:inputText> 
    
    <xp:button value="OK" id="btnConfirmPasswordOk"> 
        <xp:eventHandler event="onclick" submit="true" refreshMode="complete"> 
         <xp:this.action> 
          <xp:actionGroup> 
           <xp:executeScript> 
            <xp:this.script><![CDATA[#{javascript:try{ 
             viewScope.PWDSuccess = session.verifyPassword(viewScope.confirmPWD, HTTPPassword); 
             if (viewScope.PWDSuccess){ 
             /* RUNS NOTES AGENT */ 
             getComponent('dialogConfirmPassword').hide(); 
            } else { 
             facesContext.addMessage("messagesConfirmPassword", new javax.faces.application.FacesMessage("You have entered an incorrect password, please try again.")); 
            } 
    
           } catch (e) { 
         facesContext.addMessage("messagesConfirmPassword", new javax.faces.application.FacesMessage("ERROR! " + e.toString())); 
         viewScope.PWDSuccess = false; 
          } 
         return viewScope.PWDSuccess 
        }]]></xp:this.script> 
            </xp:executeScript> 
           </xp:actionGroup> 
          </xp:this.action> 
         </xp:eventHandler> 
        </xp:button> 
    
        <xp:outputScript> 
         <this.value><!CDATA[#{javascript:if(viewScope.PWDSuccess) {return "";}; 
         var result = "dijit.byId(\""; 
         result += getComponent("confirmPassword").getClientId(); 
         result += "\").focus();"; 
         return result; 
         }]]</this.value> 
        </xp:outputScript> 
    

    (내 머리를 형식화 - 오류를 포함합니다). 어떻게되는지 알려주세요.

  • +0

    포인터를 주셔서 감사합니다. 특히 스코프 변수에 대해서는 앞으로 이것들을 사용할 것입니다. 나에게 도움이되는 코드를 포함하도록 원래 질문을 업데이트했다. –

    +0

    서비스의 기쁜 소식 – stwissel