June 17 2016

JSF inputtext default value

JSF inputtext default value

Default values can be initialized in backing bean’s PostConstruct method. Create a method that performs all the required initialization and declared the method with javax.annotation.PostConstruct annotation.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"

<title>JSF inputtext default value</title>



<h3>JSF inputtext default value</h3>

<h:inputText id="salary" value="#{employeeManagedBean.salary}" />
<h:commandButton value="Submit"
actionListener="#{employeeManagedBean.save}" />

package com.answersz.jsf;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name = "employeeManagedBean")
public class EmployeeManagedBean {

private Integer salary;

public void initialize() {
salary = 0;

public void save() {
System.out.println("Salary :" + salary);

public Integer getSalary() {
return salary;

public void setSalary(Integer salary) {
this.salary = salary;


Copyright © 2014. All rights reserved.

Posted June 17, 2016 by answersz in category Jsf

Leave a Comment

Your email address will not be published. Required fields are marked *