JSF - h:inputHidden

Advertisements


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

JSF Tag

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

Rendered Output

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

Tag Attributes

S.N.Attribute & Description
1id
Identifier for a component
2binding
Reference to the component that can be used in a backing bean
5value
A component’s value, typically a value binding
6valueChangeListener
A method binding to a method that responds to value changes
7converter
Converter class name
11accept
Comma-separated list of content types for a form
12accept-charset
Comma- or space-separated list of character encodings for a form. The accept-charset attribute is specified with the JSF HTML attribute named acceptcharset.
14border
Pixel value for an element’s border width
44immediate
Process validation early in the life cycle

Example Application

Let us create a test JSF application to test the above tag.

StepDescription
1Create a project with a name helloworld under a package com.tutorialspoint.test as explained in the JSF - First Application chapter.
2Modify home.xhtml as explained below. Keep rest of the files unchanged.
3Compile and run the application to make sure business logic is working as per the requirements.
4Finally, build the application in the form of war file and deploy it in Apache Tomcat Webserver.
5Launch your web application using appropriate URL as explained below in the last step.

home.xhtml

<!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">
<head>
   <title>JSF Tutorial!</title>
   <h:head>
      <script type="text/javascript">
         function showHiddenValue(){ 
            alert(document.getElementById('jsfForm:hiddenField').value);	 
         }
      </script>
   </h:head>
</head>
<body>
<h2>h:inputHidden example</h2>
<hr />
   <h:form id="jsfForm">
   <h3>Get value from inputHidden field</h3>
   <h:inputHidden value="Hello World" id="hiddenField" />
   <h:commandButton value="Show Hidden Value" onclick="showHiddenValue()" />
   </h:form> 
</body>
</html>

Once you are ready with all the changes done, let us compile and run the application as we did in JSF - Create Application chapter. If everything is fine with your application, this will produce following result:

JSF h:inputHidden

Advertisements
Advertisements