JSF Showcase
h:inputText
HtmlInputText is a UIInput component that renders a field for editing single-line text.Conversion Usage
The value attribute can be converted via the converter attribute or by specifying an f:converter type of child tag. In addition, custom user feedback can be specified via the converterMessage attribute.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: Conversion to a Date using the converter attribute. --> <h:form> <h:inputText id="text" converter="javax.faces.DateTime" converterMessage="#{i18n['converter-message']}" value="#{inputTextModelBean.date}" /> <br /> <h:message for="text" /> <hr /> <h:commandButton action="#{inputTextBackingBean.submit}" value="#{i18n['submit']}"> <f:ajax execute="@form" render="@form" /> </h:commandButton> <h:outputText id="modelValue" converter="javax.faces.DateTime" value="#{inputTextModelBean.date}" /> </h:form> <!-- Example 2: Conversion to a Date using an f:converter child tag. --> <h:form> <h:inputText id="text" converterMessage="#{i18n['converter-message']}" value="#{inputTextModelBean.date}"> <f:convertDateTime pattern="MM/dd/yyyy" /> </h:inputText> <br /> <h:message for="text" /> <hr /> <h:commandButton action="#{inputTextBackingBean.submit}" value="#{i18n['submit']}"> <f:ajax execute="@form" render="@form" /> </h:commandButton> <h:outputText id="modelValue" value="#{inputTextModelBean.date}"> <f:convertDateTime pattern="MM/dd/yyyy" /> </h:outputText> </h:form> </ui:composition>
@ManagedBean @RequestScoped public class InputTextModelBean { 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 InputTextBackingBean { private static final Logger logger = LoggerFactory.getLogger(InputTextBackingBean.class); @ManagedProperty(value = "#{inputTextModelBean}") private InputTextModelBean inputTextModelBean; 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 setInputTextModelBean(InputTextModelBean inputTextModelBean) { this.inputTextModelBean = inputTextModelBean; } public void submit() { Object value = inputTextModelBean.getText(); if (value == null) { value = inputTextModelBean.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