JavaBeat

  • Home
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Privacy

JSF 2 TextArea Example

March 21, 2014 by Amr Mohammed Leave a Comment

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:

  • JSF 2 Tutorials
  • JSF Tutorials
  • Introduction to JSF

1. Managed Bean

[code lang=”java”]
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";
}

}
[/code]

  • 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

[code lang=”xml”]
<!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>
[/code]

inbox.xhtml

[code lang=”xml”]
<!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>
[/code]

3. JSF 2 InputTextArea Demo

The below snapshots show you a complete scenario for using inputTextarea component.

JSF 2 InputTextArea Example 1

JSF 2 InputTextArea Example 2

Filed Under: JSF Tagged With: JSF 2

About Amr Mohammed

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow Us

  • Facebook
  • Pinterest

As a participant in the Amazon Services LLC Associates Program, this site may earn from qualifying purchases. We may also earn commissions on purchases from other retail websites.

JavaBeat

FEATURED TUTORIALS

Answered: Using Java to Convert Int to String

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Copyright © by JavaBeat · All rights reserved