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

加里·威尔金森

我有以下对话框,当对话框具有焦点时设置密码字段焦点,但这仅在首次加载时起作用,我想在密码不匹配时设置密码字段焦点(即单击“确定”按钮并运行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>
变态

一些提示:

  • 不要追求组件之类的东西,getComponent("confirmPassword")而是将您的组件绑定到范围变量,从而编写出更好的代码
  • 您无法在您的SSJS(您指示的位置)中直接运行Client JavaScript操作
  • 您的事件处理程序永远无法正常工作,因为XPages 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>

(打倒我的头-会包含错误)。让我们知道怎么回事。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章