Software Development

JSF – Basic Form Validation for Required Fields


This post demonstrates how to perform validation on required fields in JSF.


Stuff used in this post.

  • JSF 2.2
    • javax.faces-2.2.8.jar
  • JDK 8

JSF Managed Bean

This is our managed bean is a Java class annotated with @ManagedBean. The 3 important piece of codes here are:

  1. @ManagedBean
  2. Default public no-arg constructor
  3. Setter and getter methods

For this post, the following is our Java class.


Registration Page – Request

The first page is where users input employee information. Hit Submit button to validate data and finally register an employee.


Second Page – Response

This page displays the registered employee details



With Validation Errors

The required fields are Last Name and Email. In order to test with validation error, we’ll submit the page with only First Name provided.

Request Page


The page is unable to proceed and the user sees the errors.


Without Validation Errors

Request Page


The user is then shown details of registered employee.


Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.

You Might Also Like