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" />
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 |
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; @ManagedBean(name="user") @SessionScoped 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" "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"> <h:head> <script type="text/javascript"> function printHiddenValue(){ try{ console.log(document.getElementById('myform:hiddenId').value); }catch(e){ console.log(e); } } </script> </h:head> <h:body> <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()" /> </h:form> </h:body> </html>
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.
http://localhost:8080/simple-webapp/demo.xhtml