h:inputHidden

HtmlInputHidden is a UIInput component that renders an <input> element with type=hidden.

Validation Usage

The value attribute can be validated via the validator attribute or by specifying a f:validator type of child tag. In addition, custom user feedback can be specified via the validatorMessage attribute.
This is a div that contains a hidden input



This is a div that contains a hidden input



Source Code

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:h="http://xmlns.jcp.org/jsf/html"
	xmlns:ui="http://xmlns.jcp.org/jsf/facelets">

	<!-- Example 1: Validating an email address using the validator attribute. -->
	<h:form>
		<h:outputText value="#{i18n['this-is-a-div-that-contains-a-hidden-input']}" />
		<h:inputHidden id="hidden1" binding="#{inputHidden1}"
			validator="#{inputHiddenBackingBean.emailAddressValidator}"
			validatorMessage="#{i18n['validator-message']}"
			value="#{inputHiddenModelBean.text}" />
		<h:message for="hidden1" />
		<button onclick="document.getElementById('#{inputHidden1.clientId}').value='test@liferay.com'; return false;">
			#{i18n['copy-a-valid-email-address-to-the-hidden-input']}
		</button>
		<br />
		<button onclick="document.getElementById('#{inputHidden1.clientId}').value='testliferay.com'; return false;">
			#{i18n['copy-an-invalid-email-address-to-the-hidden-input']}
			</button>
		<br />
		<button onclick="document.getElementById('#{inputHidden1.clientId}').value=''; return false;">
			#{i18n['clear-the-value-of-the-hidden-input']}
		</button>
		<hr />
		<h:commandButton action="#{inputHiddenBackingBean.submit}" value="#{i18n['submit']}">
			<f:ajax execute="@form" render="@form" />
		</h:commandButton>
		<h:outputText id="modelValue" value="#{inputHiddenModelBean.text}" />
	</h:form>

	<!-- Example 2: Validating an email address using an f:validateRegex child tag. -->
	<h:form>
		<h:outputText value="#{i18n['this-is-a-div-that-contains-a-hidden-input']}" />
		<h:inputHidden id="hidden2" binding="#{inputHidden2}"
			validatorMessage="#{i18n['validator-message']}"
			value="#{inputHiddenModelBean.text}">
			<f:validateRegex pattern=".+[@].+[.].+" />
		</h:inputHidden>
		<h:message for="hidden2" />
		<button onclick="document.getElementById('#{inputHidden2.clientId}').value='test@liferay.com'; return false;">
			#{i18n['copy-a-valid-email-address-to-the-hidden-input']}
		</button>
		<br />
		<button onclick="document.getElementById('#{inputHidden2.clientId}').value='testliferay.com'; return false;">
			#{i18n['copy-an-invalid-email-address-to-the-hidden-input']}
		</button>
		<br />
		<button onclick="document.getElementById('#{inputHidden2.clientId}').value=''; return false;">
			#{i18n['clear-the-value-of-the-hidden-input']}
		</button>
		<hr />
		<h:commandButton action="#{inputHiddenBackingBean.submit}" value="#{i18n['submit']}">
			<f:ajax execute="@form" render="@form" />
		</h:commandButton>
		<h:outputText id="modelValue" value="#{inputHiddenModelBean.text}" />
	</h:form>

</ui:composition>
@ManagedBean
@RequestScoped
public class InputHiddenModelBean {

	private Date date = new GregorianCalendar().getTime();
	private String text;

	public Date getDate() {
		return date;
	}

	public String getText() {
		return text;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public void setText(String text) {
		this.text = text;
	}
}
@ManagedBean
@RequestScoped
public class InputHiddenBackingBean {

	private static final Logger logger = LoggerFactory.getLogger(InputHiddenBackingBean.class);

	@ManagedProperty(value = "#{inputHiddenModelBean}")
	private InputHiddenModelBean inputHiddenModelBean;

	public void emailAddressValidator(FacesContext facesContext, UIComponent uiComponent, Object value)
		throws ValidatorException {

		if (value != null) {

			if (!value.toString().matches(".+[@].+[.].+")) {
				FacesMessage facesMessage = new FacesMessage();
				facesMessage.setSeverity(FacesMessage.SEVERITY_ERROR);
				throw new ValidatorException(facesMessage);
			}
		}
	}

	public void setInputHiddenModelBean(InputHiddenModelBean inputHiddenModelBean) {
		this.inputHiddenModelBean = inputHiddenModelBean;
	}

	public void submit() {

		Object value = inputHiddenModelBean.getText();

		if (value == null) {
			value = inputHiddenModelBean.getDate();
		}

		logger.info("You entered: " + value);
	}

	public void valueChangeListener(ValueChangeEvent valueChangeEvent) {

		FacesContext facesContext = FacesContext.getCurrentInstance();
		PhaseId phaseId = facesContext.getCurrentPhaseId();
		logger.debug("valueChangeListener: phaseId=[{0}]", phaseId.toString());

		String phaseName = phaseId.toString();
		FacesMessage facesMessage = new FacesMessage("The valueChangeListener method was called during the " +
				phaseName + " phase of the JSF lifecycle.");
		facesContext.addMessage(null, facesMessage);
	}
}
Liferay Faces Bridge Implementation 5.0.0 + Showcase Common 3.1.1 + Liferay Faces Util 3.4.1 + Mojarra 2.2.20