JSF 2 h inputHidden

JSF 2 h inputHidden


Posted in : Java Posted on : July 10, 2012 at 7:21 PM Comments : [ 0 ]

In this tutorial you will learn about the tag in JSF 2.

JSF 2 h inputHidden

In this tutorial you will learn about the <h:inputHidden> tag in JSF 2.

<h:inputHidden> tag in JSF 2 is translated into the HTML <input> element of type 'hidden'. This tag is used to send the variables from one page to other page without showing the value to the user. The 'value' attribute of this tag is rendered by rendering the current value of the component and the 'name' attribute is encoded by rendering clientId of the component. Value of the <input> element are invisible to a user. However, to show the value of <h:inputHidden> component another mechanism can be used such as use of JavaScript.

Attributes of <h:inputHidden>

  • converter : An optional attribute, is used when you are required to invoke a Converter (if any).
  • converterMessage : An optional attribute, is used to display a textual converter message, converter message given by the Converter is replaced with converterMessage (if present).

  • id : An optional attribute, this attribute is an unique identifier. If this attribute is present it makes the component uniquely identifiable.
  • immediate : An optional attribute that evaluates a boolean value which specifies whether the value of component must be converted and validated on Apply Request Value phase instead of waiting for the Process Validations phase or not.

  • rendered : An optional attribute that evaluates to a boolean value which specifies whether the current component should be rendered in the Rendered Response phase or not or worked on any later form submission. The default value of this attribute is defined to true.

  • required : An optional attribute that evaluates to a boolean value which specifies that the submitted value of this component is necessary or not.
  • requiredMessage : An optional attribute, is used as to display the required textual validation message if the required attribute is used.
  • validator : An optional attribute, is used when you are required to invoke a Validator (if any).
  • validatorMessage : An optional attribute, is used to display a textual validator message, validator message given by the Validator is replaced with validatorMessage (if present).

  • value : An optional attribute, is used to specify the current value of component.
  • valueChangeListener : An optional attribute, is used when you are required to invoke a valueChangeListener method to notified on the change of component's new value.

  • binding : An optional attribute that evaluates to a javax.faces.component.UIComponent specified for linking the component with the property of backing bean.

Example :

Here I am giving an jsf 2 <h:inputHidden> example. This example will demonstrate you how to use the <h:inputHidden> tag in JSF. In this example I have created a simple JSF page where I have used the <h:inputHidden> tag. Here I want to recall you that when a JSF page will be rendered, the output for the <h:inputHidden> will be invisible.

Directory Structure

NameBean.java

package devmanuals;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean(name="nameBean")
@RequestScoped
public class NameBean {

String name;
String country = "India";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
} 
}

index.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"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<head>
<title>JSF 2 html inputHidden</title>
</head>
<body>
<f:view>
<h:form>
<h:outputText value="Enter Name : "/>
<h:inputText value="#{nameBean.name}"/> <br/>
<h:inputHidden value="#{nameBean.country}" /> <br/>
<h:commandButton value="submit" action="output" />
</h:form>
</f:view>
</body>
</html>

output.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"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">

<head>
</head>
<body>
<f:view>
<h:outputText value="Your Name is : #{nameBean.name}" /> <br/>
</f:view>
</body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>jsfHInputHidden</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
<url-pattern>*.jsf</url-pattern>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
</web-app>

How to run this example :

Download the source code from the link Download Source Code provided in the WAR file and then import the source code in Eclipse IDE as a WAR file and then select the imported file and then press the Right Click -> Run As ->Run on Server and then Click Finish button.

Output :

When you will execute the above example you will see all the output for the tags used inside the JSF pages but there will be no output visible for the <h:inputHiddden> tag but in the HTML source code you can see the rendered <input> element of type 'hidden'.

HTML Source Code after the view pages rendered to the HTML page is as follows :

<!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 2 html inputHidden</title>
</head>
<body>
<form id="j_idt3" name="j_idt3" method="post" action="/jsfHInputHidden/index.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_idt3" value="j_idt3" />
Enter Name : <input type="text" name="j_idt3:j_idt5" /> <br /><input type="hidden" name="j_idt3:j_idt7" value="India" /> <br /><input type="submit" name="j_idt3:j_idt9" value="submit" /><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="H4sIAAAAAAAAAJVSz2sTQRR+3SStjVH6Q3LTUxEEmSASFENpgm1ocKuBrWLxoJPdaXfi7O448zbZFCn4HwiehIpXD978C8SDIFjQo/+DR+/ObGJTRQ8+mLe7b+d773vve2+/Q0lqBYt9OqAkRS7IJtXhFpWluW/vP1QffSmA04aySGjQpj4mqgPzGCqmw0QEmVxrgrXK8JTxC+YUEWb7D3mAV1MFyw/cPK+g8R650+szHxvPj+6/XtCXhAOQSQMoSWPpEziAgv06UEAsJiO71Gea+Ekkk5jFSO52bv56X+mqRDKFo1tspGFiSyahgrPTghtxGp38KRHKFFHxXopMa1sSJvxnc/72zCBcMDWJTuMJA+sFQ01a3a7b2Vg306r/4waPpCDrbJemAtvj4EpLSjHaTh6z+MebyzuHzX6zYrkMq1Cp8ThgGclCjISpfF3eO3qaZWYC9f+bQFfxAUV2slfb3BzCuWm/2yHFlmKe4WmEmcrdUoqOXK4xe/b1/MuP9FUBZjpQ1Hyf5fo4w6L1BnTx76w8NLU3zTYw5dEBUzuf3q2+OPy85YDjwrwvqNa3acQQlvJlqFltap6hFe81XChrgwnyHAjV8Q2e1DymOBV8n/YEa2RSDmxDi7lmy9L601bOM+NNu5E/rh0vUdGuFELJhq8cRx35J6L+OyL7CUWnQWYNAwAA" autocomplete="off" />
</form>
</body>
</html>
Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics