0

I am writing a basic login screen with textboxes for username and password, a submit button and a commandLink to redirect to a page to retrieve password. I have set required = true for both text fields and set a required message too. Now, if i need to redirect to the retrieve password page without entering any text in the textboxes, it wont let me. Kindly help.

<?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>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Adarsh
  • 3,613
  • 2
  • 21
  • 37

1 Answers1

2

Any command component submits and processes (and validates!) by default the entire form. You merely want to perform page-to-page navigation. The <p:commandLink> is the wrong tool therefor. You should be using <h:link> instead.

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

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • BalusC, do h:link and h:outputlink produce the same result ? I checked the html and from what I could find on the internet, the only difference is that h:outputlink can be used along with parameters – Adarsh Nov 18 '13 at 20:58
  • The `` takes a JSF (implicit) navigation case outcome. The `` takes an URL. The `` can be used on both. See also the first "See also" link. I don't put those links on my answers for decoration only. They actually point to some more in-depth background information and/or useful additional information. – BalusC Nov 18 '13 at 20:59