In JSF, you can use the <h:inputTextarea /> tag to render a HTML textarea field. For example,

JSF tag…

<h:inputTextarea cols="30" rows="10" />

Render this HTML code…

<textarea name="random value" cols="30" rows="10"></textarea>

JSF textarea example

A full JSF 2 example to render a textarea field via <h:inputTextarea /> tag.

1. Managed Bean

A managed bean, declared as name “user”.

package com.mkyong.form;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import java.io.Serializable; @ManagedBean(name="user")
@SessionScoped
public class UserBean implements Serializable { private String address; public String getAddress() {
return address;
} public void setAddress(String address) {
this.address = address;
} }

2. View Page

Two pages for the demonstration.

demo.xhtml – render a textarea field via “h:inputTextarea”, button via “h:commandButton”, if the button is clicked, textarea value will be submitted to the “userBean.address’ property via setAddress() method, and forward to “user.xhtml”.

<?xml version="1.0" encoding="UTF-8"?>
<!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:h="http://java.sun.com/jsf/html"> <h:body>
<h1>JSF 2 textarea example</h1> <h:form>
<table>
<tr>
<td valign="top">Address :</td>
<td><h:inputTextarea value="#{user.address}" cols="30" rows="10" /></td>
</tr>
</table>
<h:commandButton value="Submit" action="user" />
</h:form> </h:body>
</html>

user.xhtml – display the submitted textarea value via “h:outputText

<?xml version="1.0" encoding="UTF-8"?>
<!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:h="http://java.sun.com/jsf/html"> <h:body>
<h1>JSF 2 textarea example</h1> Address : <h:outputText value="#{user.address}" />
</h:body>
</html>

3. Demo

URL : http://localhost:8080/JavaServerFaces/

Display “demo.xhtml” page

If the button is clicked, display “user.xhtml” page, and also the submitted textarea value.

最新文章

  1. Make Helix Curve in OpenCASCADE
  2. php 使用htmlspecialchars() 和strip_tags函数过滤HTML标签的区别
  3. XML实体注入漏洞
  4. 谈谈你对http的理解
  5. sublime Text2 2.0.2 build 2221 64位 破解(已测试)
  6. int main(int argc,char* argv[]) 简单理解
  7. Tick and Tick
  8. iframe 自适应内容高度
  9. GYM 101617 F
  10. Git换行符是如何精确控制的
  11. go xorm增删改查
  12. Mac os fatal error: &#39;numpy/arrayobject.h&#39; file not found
  13. CyclicBarrier循环屏障相关
  14. iOS记录一常用的方法和语句
  15. Oracle安装部署之linux OS install oracle database安装脚本
  16. windows7,windows8 64位系统 IIS7.0配置.net网站时报错:未能加载文件或程序集“XXX”或它的某一个依赖项。试图加载格式不正确的程序。
  17. P2319 [HNOI2006]超级英雄 题解
  18. cloudera-scm-server启动时出现Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection问题解决方法(图文详解)
  19. Microservices with Spring Boot
  20. Babel编译

热门文章

  1. 自定义View(4)Canvas和Paint常用绘制函数
  2. *像word一样编辑复杂的文本:SpannableString 样式详介
  3. oracle db shutdown immediate&ndash;multi Instance
  4. Android开发之TextView实现跑马灯效果
  5. 面试题_17_to_30_数据类型和 Java 基础面试问题
  6. JasperReports+iReport打印为excel表头重复问题解决
  7. 函数buf_read_page_low
  8. Codeforces Round #270
  9. Java知识点:琐碎知识点(3)
  10. LeetCode Best Time to Buy and Sell Stock 买卖股票的最佳时机 (DP)