JSF Tutorial - JSF Hidden Value Example

The h:inputHidden tag renders an HTML input element of the type "hidden".

The following JSF tag

<h:inputHidden value="Hello World" id="hiddenField" />

is rendered to the following HTML tag.

<input id="jsfForm:hiddenField" type="hidden" name="jsfForm:hiddenField" 
   value="Hello World" />

Tag Attributes

idid for the tag
bindingReference to the component used in a backing bean
valuevalue binding
valueChangeListenerA method binding that responds to value changes
converterConverter class name
acceptComma-separated list of content types for a form
accept-charsetComma- or space-separated list of character encodings for a form.
borderPixel value for an element's border width
immediateProcess validation early in the life cycle


The following code is from UserBean.java.

package com.java2s.common;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import java.io.Serializable;

public class UserBean implements Serializable {

  String answer = "I'm Hidden value!";

  public String getAnswer() {
    return answer;

  public void setAnswer(String answer) {
    this.answer = answer;


The following code is from demo.xhtml.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns="http://www.w3.org/1999/xhtml"   

  <script type="text/javascript">
    function printHiddenValue(){
      <h1>JSF 2 hidden value example</h1>
    <h:form id="myform">
        <h:inputHidden value="#{user.answer}" id="hiddenId" />
        <h:commandButton type="button" value="ClickMe" onclick="printHiddenValue()" />

Download Hidden_Value.zip


Copy the generated WAR file from the target folder to Tomcat deployment folder and run Tomcat-Install-folder/bin/startup.bat.

After Tomcat finish starting, type the following URL in the browser address bar.