JavaServer Faces (JSF 2) provides a number of user interfaces components that cover the most common requirements, one of the most important component is a <h:inputTextarea/> component. The inputTextarea component renders an HTML AreaText element. If you are looking for the configuration of complete application, please read our JSF 2 Setup Tutorial.
Also Read:
1. Managed Bean
package net.javabeat.jsf; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; @ManagedBean @SessionScoped public class MessageBean { private String message = ""; public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public String sendMessage() { return "inbox"; } }
- The managed bean (MessageBean) contains a property of type String called message.
- The managed bean (MessageBean) provides an action for navigating from writing message page into viewing of message page.
2. The Views
message.xhtml
<!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:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <f:view> <h:form> <h1><h:outputText value="JavaBeat JSF 2.2 Examples" /></h1> <h2><h:outputText value="Text Area Example" /></h2> <h:inputTextarea cols="20" rows="10" value="#{messageBean.message}"></h:inputTextarea> <h:commandButton value="Send" action="#{messageBean.sendMessage}"></h:commandButton> </h:form> </f:view> </html>
inbox.xhtml
<!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:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <f:view> <h:form> <h1><h:outputText value="JavaBeat JSF 2.2 Examples" /></h1> <h2><h:outputText value="Text Area Example" /></h2> <h:outputLabel value="#{messageBean.message}"/> </h:form> </f:view> </html>
3. JSF 2 InputTextArea Demo
The below snapshots show you a complete scenario for using inputTextarea component.