Pre-populating the form values in JSF with Example

Hey guys in this, we will discuss populating the form values in JSF with Example.


  • To create textbox we use <h:inputText> tag
  • To create dropdown menu we use <h:selectOneMenu> tag, we will use <c:selectItem> tag to add the dropdown options
  • To create a checkbox we use <h:selectManyCheckbox> tag. We will use  <c:selectItem> tag to add the checkbox options
  • To create radio button we use <h:selectOneRadio> tag, we will use <c:selectItem> tag to add radio button options.

Complete example

We will create this example step by step, follow this tutorial till the end

Read More:

Create Dynamic Web Project

To create a dynamic web project, you can read the following tutorial

Create a bean

Create inside the in.bushansirgur.jsf.beans package and add the following content

package in.bushansirgur.jsf.beans;

import java.util.Arrays;
import java.util.List;

import javax.faces.bean.ManagedBean;

public class Register {
	private String email;
	private String role;
	private String active;
	private String[] permissions; 
	public Register() { = "[email protected]";
		this.role = "Power Admin"; = "Inactive";
		this.permissions = new String[]{"Create", "Read"}; 

	public String getEmail() {
		return email;

	public void setEmail(String email) { = email;

	public String getRole() {
		return role;

	public void setRole(String role) {
		this.role = role;

	public String getActive() {
		return active;

	public void setActive(String active) { = active;
	public String[] getPermissions() {
		return permissions;

	public void setPermissions(String[] permissions) {
		this.permissions = permissions;

Create Input form

Create register-form.xhtml file inside the WebContent and add the following content

<!DOCTYPE html>
<html xmlns=""

		<title>Input Form</title>
			Email: <h:inputText id="email" value="#{}" />
			<h:selectOneMenu value="#{register.role}">
				<c:selectItem itemValue="Admin" itemLabel="Admin" />
				<c:selectItem itemValue="Super Admin" itemLabel="Super Admin" />
				<c:selectItem itemValue="Power Admin" itemLabel="Power Admin" />
			<h:selectOneRadio value="#{}">
				<c:selectItem itemValue="Active" itemLabel="Active" />
				<c:selectItem itemValue="Inactive" itemLabel="Inactive" />
			<h:selectManyCheckbox value="#{register.permissions}">
				<c:selectItem itemValue="Create" itemLabel="Create" />
				<c:selectItem itemValue="Read" itemLabel="Read" />
				<c:selectItem itemValue="Update" itemLabel="Update" />
				<c:selectItem itemValue="Delete" itemLabel="Delete" />
				<c:selectItem itemValue="All" itemLabel="All" />
			<h:commandButton value="Register" action="dashboard" />


Run the app

To run the application, right click on the project, select Run As -> choose Run on Server

Open the browser, navigate to the URL http://localhost:8080/JSF-hello-world/faces/register-form.xhtml

That’s it for this post. If you like this post, then please share this with your friends and collogues. Also share this post on your social media profiles as well.

Bushan Sirgur

Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.

Leave a Reply