JSF h:inputHidden tag is used to render a HTML hidden field.
JSF tag:
<h:inputHidden value="Hello World" id="hiddenField" /> |
Rendered HTML tag:
<input id="jsfForm:hiddenField" name="jsfForm:hiddenField" type="hidden" value="Hello World" /> |
Attributes of h:inputHidden tag.
Attribute | Description |
---|---|
id | id for the tag |
binding | Reference to the component used in a backing bean |
value | value binding |
valueChangeListener | A method binding that responds to value changes |
converter | Converter class name |
accept | Comma-separated list of content types for a form |
accept-charset | Comma- or space-separated list of character encodings for a form. |
border | Pixel value for an element’s border width |
immediate | Process validation early in the life cycle |
Example:
test.xhtml
<?xml version="1.0" encoding="UTF-8"?> <!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"> <h:head> <title>JSF input hidden example.</title> </h:head> <h:body> <h2>JSF input hidden example.</h2> <h:form> <h:inputHidden value="#{test.hiddenValue}"/> <br/> <br/> <h:commandButton value="Check Hidden Value" action="#{test.checkHiddenValue}"/> </h:form> </h:body> </html> |
Test.java
import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; /** * Managed bean. * @author w3schools */ @ManagedBean(name="test") @SessionScoped public class Test { private String hiddenValue = "JSF Example."; public String getHiddenValue() { return hiddenValue; } public void setHiddenValue(String hiddenValue) { this.hiddenValue = hiddenValue; } public String checkHiddenValue() { if(hiddenValue == null || hiddenValue.equals("")){ return "fail"; }else{ return "success"; } } } |
faces-config.xml
<?xml version="1.0" encoding="windows-1252"?> <faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"> <navigation-rule> <from-view-id>test.xhtml</from-view-id> <navigation-case> <from-outcome>success</from-outcome> <to-view-id>welcome.xhtml</to-view-id> </navigation-case> <navigation-case> <from-outcome>fail</from-outcome> <to-view-id>test.xhtml</to-view-id> </navigation-case> </navigation-rule> </faces-config> |
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <servlet> <servlet-name>faces</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>faces</servlet-name> <url-pattern>/faces/*</url-pattern> </servlet-mapping> </web-app> |
welcome.xhtml
<?xml version="1.0" encoding="UTF-8"?> <!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"> <h:head> <title>JSF input hidden example.</title> </h:head> <h:body> <h3>Hidden value: <h:outputText value="#{test.hiddenValue}"/></h3> </h:body> </html> |
URL:
http://localhost:7001/JSFExample7/faces/test.xhtml
Output:
Click on Check Hidden Value button.
Download this example.