Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF 2.0: Validate equality of 2 InputSecret Fields (confirm password) without writing Code?

I'm developing a pure JavaEE6 application with JSF 2.0 and Glassfish. My JSF implementation is Primefaces (beside Mojarra provided by Glassfish).

I want to verify if the values of 2 password fields in a JSF form are equal. With Seam, there is the neat component <s:validateEquality for="pw1"/>. I want do to the same without Seam, just using JSF (or maybe a component of a JSF library). Until now i only saw examples which validate the form with a custom validator. But i would like to compare the fields without writing Java code or Javascript code. Is that possible?

This what it looks like with Seam:

...
<h:inputSecret id="passwort" value="#{personHome.instance.password}" 
    redisplay="true" required="true">
  <f:validateLength minimum="8"/>
  <a:support event="onblur" reRender="passwortField" bypassUpdates="true" ajaxSingle="true" />
</h:inputSecret>
...    
<h:inputSecret id="passwort2" required="true" redisplay="true">
  <!-- find the JSF2.0-equivalent to this tag: -->
  <s:validateEquality for="passwort"/>
  <a:support event="onblur" reRender="passwort2Field" bypassUpdates="true" ajaxSingle="true" />
</h:inputSecret>
...
like image 678
Wolkenarchitekt Avatar asked May 25 '10 22:05

Wolkenarchitekt


People also ask

What is the use of inputsecret in JSF?

JSF <h:inputSecret> Tag It is a standard password field which accepts one line of text with no spaces and displays it as a set of asterisks as it is entered. In other words, we say, it is used to create a HTML password field which allows a user to input a string without the actual string appearing in the field.

Is there a custom validator in JSF 2?

Custom validator in JSF 2.0 By mkyong| Last updated: October 18, 2012 Viewed: 216,291 (+27 pv/w) Tags:jsf2| validation

How to retrieve the value in the first password field?

The value in the first password field is retrieved from the UI component named “password” that is the id from the JSF page. Another potential problem can occur if a user fills in only one of the password fields. This will result in null values. Therefore, a test for null-ness has been added to the if statement:

What is the use of inputsecret tag in HTML?

In other words, we say, it is used to create a HTML password field which allows a user to input a string without the actual string appearing in the field. It holds the current value of inputSecret tag.


1 Answers

You may use Primefaces tag in this very simple way:

<p:password id="password" value="#{bean.password}" match="repeated_password" />

<p:password id="repeated_password" value="#{bean.password}" />
like image 107
FloatOverflow Avatar answered Oct 03 '22 10:10

FloatOverflow