How can I validate password with confirm password in login.jsp and only if equal, then redirect to success.jsp which displays Welcome #{beans.username}.
How can I validate password with confirm password in login.jsp and only if equal,
Share
Just implement a
Validatorthe usual way. Validation should surely not be done in the action method as others suggest/imply. If validation fails, then by default the action method just won’t be invoked and the same page will just be redisplayed with validation errors. You can pass the password field as<f:attribute>of the confirm password field so that the validator can get hold of its value for test.Here’s a kickoff example of the view:
and the validator:
The message will appear in
<h:message for="confirm">.Note that you only need to have the password as a property in the backing bean, not the confirm password.
In the action method you can just return the navigation case outcome the usual way:
Since JSF 2.0 there’s no need for verbose navigation cases in
faces-config.xmlanymore as the other answer suggest.Unrelated to the concrete problem, why are you still sticking to the legacy JSP view technology? This has been deprecated since JSF 2.0 in favor of Facelets. Please consider migrating JSP to Facelets. Then you’ll be able to use among others the new JSF 2.0
<f:ajax>awesomeness and strong Facelets templating capabilities.