h:inputTextarea

HtmlInputTextarea is a UIInput component that renders a field for editing multi-line text.

General Usage

The value attribute can be bound to a model bean property via EL.

Source Code

  1. <ui:composition xmlns="http://www.w3.org/1999/xhtml"
  2. xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:h="http://xmlns.jcp.org/jsf/html"
  3. xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
  4.  
  5. <h:form>
  6. <h:inputTextarea id="textarea" label="#{i18n['text-field']}"
  7. required="#{showcaseModelBean.selectedComponent.required}" value="#{inputTextModelBean.text}" />
  8. <h:message for="textarea" />
  9. <hr />
  10. <h:commandButton action="#{inputTextBackingBean.submit}" value="#{i18n['submit']}">
  11. <f:ajax execute="@form" render="@form" />
  12. </h:commandButton>
  13. <h:outputText id="modelValue" value="#{inputTextModelBean.text}" />
  14. </h:form>
  15.  
  16. </ui:composition>
  1. @ManagedBean
  2. @RequestScoped
  3. public class InputTextModelBean {
  4.  
  5. private Date date = new GregorianCalendar().getTime();
  6. private String text;
  7.  
  8. public Date getDate() {
  9. return date;
  10. }
  11.  
  12. public String getText() {
  13. return text;
  14. }
  15.  
  16. public void setDate(Date date) {
  17. this.date = date;
  18. }
  19.  
  20. public void setText(String text) {
  21. this.text = text;
  22. }
  23. }
  1. @ManagedBean
  2. @RequestScoped
  3. public class InputTextBackingBean {
  4.  
  5. private static final Logger logger = LoggerFactory.getLogger(InputTextBackingBean.class);
  6.  
  7. @ManagedProperty(value = "#{inputTextModelBean}")
  8. private InputTextModelBean inputTextModelBean;
  9.  
  10. public void emailAddressValidator(FacesContext facesContext, UIComponent uiComponent, Object value)
  11. throws ValidatorException {
  12.  
  13. if (value != null) {
  14.  
  15. if (!value.toString().matches(".+[@].+[.].+")) {
  16. FacesMessage facesMessage = new FacesMessage();
  17. facesMessage.setSeverity(FacesMessage.SEVERITY_ERROR);
  18. throw new ValidatorException(facesMessage);
  19. }
  20. }
  21. }
  22.  
  23. public void setInputTextModelBean(InputTextModelBean inputTextModelBean) {
  24. this.inputTextModelBean = inputTextModelBean;
  25. }
  26.  
  27. public void submit() {
  28.  
  29. Object value = inputTextModelBean.getText();
  30.  
  31. if (value == null) {
  32. value = inputTextModelBean.getDate();
  33. }
  34.  
  35. logger.info("You entered: " + value);
  36. }
  37.  
  38. public void valueChangeListener(ValueChangeEvent valueChangeEvent) {
  39.  
  40. FacesContext facesContext = FacesContext.getCurrentInstance();
  41. PhaseId phaseId = facesContext.getCurrentPhaseId();
  42. logger.debug("valueChangeListener: phaseId=[{0}]", phaseId.toString());
  43.  
  44. String phaseName = phaseId.toString();
  45. FacesMessage facesMessage = new FacesMessage("The valueChangeListener method was called during the " +
  46. phaseName + " phase of the JSF lifecycle.");
  47. facesContext.addMessage(null, facesMessage);
  48. }
  49. }
Liferay Faces Bridge Implementation 5.0.0 + Showcase Common 3.1.1 + Liferay Faces Util 3.4.1 + Mojarra 2.2.20