JSF Showcase

Note

Please consider using showcase:field h-field-benefits-description

h:outputLabel

HtmlOutputLabel is a UIOutput component that renders its value attribute within a <label> element.

General Usage

The value attribute can be bound to a message-bundle property via EL in order to render internationalized labels.

If the component is associated with an input component like h:inputText via the for attribute, then a validation FacesMessage that is queued for the associated component will use the value of the label. This provides the end-user with a better context as to which input field failed validation.
*

Source Code

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

	<h:form>
		<h:messages globalOnly="true" layout="table" />
		<h:panelGroup id="container" layout="block" styleClass="form-inline">
			<h:outputLabel for="firstName" 
				value="#{i18n['first-name']}" />
			<h:inputText id="firstName" required="true" value="#{fieldModelBean.firstName}">
				<f:ajax render="container modelValue" />
			</h:inputText>
			<h:outputText value="*" />
			<h:message for="firstName" />
		</h:panelGroup>
		<hr />
		<h:commandButton action="#{fieldBackingBean.submit}" value="#{i18n['submit-and-re-render-form']}">
			<f:ajax execute="@form" render="@form" />
		</h:commandButton>
		<h:outputText id="modelValue" value="#{fieldModelBean.firstName}" />
	</h:form>

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

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

	@ManagedProperty(value = "#{fieldModelBean}")
	private FieldModelBean fieldModelBean;

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

		FacesMessage facesMessage = new FacesMessage();
		facesMessage.setSeverity(FacesMessage.SEVERITY_ERROR);
		facesMessage.setDetail("This is an error message.");
		facesContext.addMessage(uiComponent.getClientId(), facesMessage);
	}

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

		FacesMessage facesMessage = new FacesMessage();
		facesMessage.setSeverity(FacesMessage.SEVERITY_INFO);
		facesMessage.setDetail("This is an info message.");
		facesContext.addMessage(uiComponent.getClientId(), facesMessage);
	}

	public void setFieldModelBean(FieldModelBean fieldModelBean) {
		this.fieldModelBean = fieldModelBean;
	}

	public void submit() {

		FacesMessage globalFacesMessage = new FacesMessage("Your request processed successfully.");
		FacesContext facesContext = FacesContext.getCurrentInstance();
		facesContext.addMessage(null, globalFacesMessage);

		logger.info("submit: firstName = " + fieldModelBean.getFirstName());
	}

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

		FacesMessage facesMessage = new FacesMessage();
		facesMessage.setSeverity(FacesMessage.SEVERITY_WARN);
		facesMessage.setDetail("This is a warning message.");
		facesContext.addMessage(uiComponent.getClientId(), facesMessage);
	}
}
Liferay Faces Bridge Implementation 4.1.0 + Showcase Common 3.0.1 + Liferay Faces Util 3.1.0 + Mojarra 2.2.14