在对话框(扩展库对话框)中验证后设置字段焦点

时间:2014-04-16 15:43:16

标签: xpages xpages-extlib

我有以下对话框,当对话框有焦点时设置密码字段焦点,但这仅在首次加载时有效,我想在密码不匹配时设置密码字段焦点(即点击后确定按钮并运行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 个答案:

答案 0 :(得分:1)

一些指示:

  • 不要追求getComponent("confirmPassword")之类的组件,而是将组件绑定到范围变量,制作更好的代码
  • 您无法在SSJS(您指明的地方)
  • 中直接运行客户端JavaScript操作
  • 您的事件处理程序永远不会起作用,因为XPage ID与客户端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>

(键入我的头 - 将包含错误)。 让我们知道它是怎么回事。