JSF2 Password Field Example


In this example, we will see how to add a password field in a JSF page using the <h:inputSecret ../>  tag.

Password field is similar to text field,  the difference is that the characters in the password field are masked (shown as dots on the screen).


1. Project structure

JSF2 Password Field Example


2. JSF pages

In the index page, we will add a password field and link it to the pwd attribute of the user bean.

File : index.xhtml

The <h:inputSecret ..> will render an HTML input element of type password.


In the result page, we will display the value of the password input submitted from the index page.

File : result.xhtml


3. Managed bean



4. Test It

Open the browser and type : http://localhost:8080/JSF2-Password-Field-Example/index.jsf

Enter a password value in the password field and press the button.

JSF2 Password Field Example 1


JSF2 Password Field Example 2


Download source code