导航到“忘记密码”页面时跳过验证

时间:2013-11-18 20:34:58

标签: jsf-2 primefaces

我正在编写一个基本的登录屏幕,其中包含用于用户名和密码的文本框,一个提交按钮和一个用于重定向到页面以检索密码的commandLink。我为两个文本字段设置了required = true,并设置了所需的消息。现在,如果我需要重定向到检索密码页面而不在文本框中输入任何文本,它就不会让我。请帮助。

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"        
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<ui:composition template="/template/Template.xhtml">
    <ui:define name="title">Login</ui:define>
    <ui:define name="pageContent">
        <h:form>
            <p:messages id="message1" closable="true"/>
            <p:panelGrid id="loginPanel" columns="2"
                style="margin-left: auto;margin-right: auto;margin-top: 10%;border-style:none">
                <h:outputLabel for="uName" value="User Name "></h:outputLabel>
                <p:inputText id="uName" value="#{loginBean.uName}" required="true"
                    requiredMessage="#{prop.userNameRequired}"></p:inputText>
                <h:outputLabel for="passwrd" value="Password "></h:outputLabel>
                <p:password id="passwrd" value="#{loginBean.passwrd}"
                    required="true" requiredMessage="#{prop.passwordRequired}"></p:password>
            </p:panelGrid>
            <p:commandButton id="login" value="Login"
                style="margin-left: 40%;margin-top: 2%"
                action="#{loginBean.authenticate}" ajax="false"></p:commandButton>
            <p:spacer></p:spacer>
            <p:commandLink id="forgotPass" value="Forgot User-Name/Password ?"
                style="margin-left: 4.5%;font-size:0.7em" action="ForgotPassword.xhtml?faces-redirect=true"></p:commandLink>                                                                  
        </h:form>
    </ui:define>
</ui:composition>
</h:body>
</html>

1 个答案:

答案 0 :(得分:2)

任何命令组件默认提交并处理(并验证!)整个表单。您只想执行页面到页面的导航。 <p:commandLink>是错误的工具。您应该使用<h:link>代替。

<h:link id="forgotPass" value="Forgot User-Name/Password ?"
    style="margin-left: 4.5%;font-size:0.7em" outcome="ForgotPassword.xhtml" />

另见: