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.

JSF 2 textarea example的更多相关文章

  1. JSF标签大全详解

    1. JSF入门 藉由以下的几个主题,可以大致了解JSF的轮廓与特性,我们来看看网页设计人员与应用程序设计人员各负责什么. 1.1简介JSF Web应用程序的开发与传统的单机程序开发在本质上存在着太多 ...

  2. div实现自适应高度的textarea,实现angular双向绑定

    相信不少同学模拟过腾讯的QQ做一个聊天应用,至少我是其中一个. 过程中我遇到的一个问题就是QQ输入框,自适应高度,最高高度为3row. 如果你也像我一样打算使用textarea,那么很抱歉,你一开始就 ...

  3. JQuery 复制粘贴上传图片插件(textarea 和 tinyMCE)

    开源地址:https://github.com/yuezhongxin/paste-upload-image.js 支持 Ctrl+C/Ctrl+V 上传,支持拖拽上传,也支持 QQ/微信截图上传. ...

  4. div仿textarea使高度自适应

    今天真的有些无语,在百度上找了很多关于textarea和input高度自适应的代码,并且考虑到了要判断textarea的滚动条,从而动态改变它的高度,直到我搜索了这个让我目瞪狗呆的办法…… <d ...

  5. 使用JQuery统计input和textarea文字输入数量代码

    本文主要介绍了jQuery实现统计输入文字个数的方法,需要的朋友可以参考下. HTML部分: <input type="text" value="我是输入的文字&q ...

  6. 取消chrome浏览器下input和textarea的默认样式;html5默认input内容清除“×”按钮去除办法

    取消chrome浏览器下input和textarea的默认样式: outline:none;/*清空chrome中input的外边框*/ html5默认input内容清除“×”按钮去除办法: inpu ...

  7. textarea 中的 innerHTML 和 value

    <textarea></textarea> <input type="button" value="click" /> &l ...

  8. JSF primefaces dataTable paginator 表格分页 问题

    当第一次查询返回list列表,分页1,2,3.....这是选择2,当前页面停留在第2页. 当再次查询后,因为使用的ajax,结果更新了,但当前页面依旧是第2页. 可以在jsf页面,datatable的 ...

  9. 关于JSF中immediate属性的总结(二)

    The immediate attribute in JSF is commonly misunderstood. If you don't believe me, check out Stack O ...

随机推荐

  1. ffmpeg 2.8.1 最新版本 VS2013 可调式动态库

    ffmpeg 2.8.1 最新版本 VS2013 可调式动态库 由于大多数初学者都在想尽各种版本寻求VC编译调试ffmpeg的版本,我也曾经移植过几个版本的ffmpeg到VC上编译.: 链接所需动态库 ...

  2. HDU 1695 (莫比乌斯反演) GCD

    题意: 从区间[1, b]和[1, d]中分别选一个x, y,使得gcd(x, y) = k, 求满足条件的xy的对数(不区分xy的顺序) 分析: 虽然之前写过一个莫比乌斯反演的总结,可遇到这道题还是 ...

  3. 【Java学习笔记】函数使用

    package aaa; public class aaa { public static int add(int a,int b) { return a+b; } public static voi ...

  4. shell脚本实例

    备注:一些与传递给shell的参数相关的变量:$# 命令行参数的个数$? 调用命令的返回值$$ 当前进程的进程号$! 最后一个后台命令的进程号$0 命令行的第一个参数,也就是命令名$n 命令行的第n个 ...

  5. RTMP协议详解(转)

    转自<RTMP协议详解(一) (二) (三) > Real Time Messaging Protocol(实时消息传送协议协议)是Adobe Systems公司为Flash播放器和服务器 ...

  6. MVC ActionResult -- JavaScriptResult,JsonResult

    以下是ActionResult的继承图: 大概的分类: EmptyResult:表示不执行任何操作的结果 ContentResult :返回文本结果 JavaScriptResult:返回结果为Jav ...

  7. angular+rails集成实战

    http://start.jcolemorrison.com/setting-up-an-angularjs-and-rails-4-1-project/ 1. 添加gemgem 'sprockets ...

  8. cgroup的测试数据

    [root@xxxx /cgroup/memory/rule3021]#cat memory.limit_in_bytes503316480   480M [root@xxxx /cgroup/mem ...

  9. CPC23-4 K.喵喵的神·数

    题意:给出整数T,P,求c(T,P) mod P. 解法:用卢卡斯定理. 卢卡斯定理:解决c(n,m) mod p问题.Lucas(n,m,p)=c(n%p,m%p)*Lucas(n/p,m/p,p) ...

  10. mybatis实战教程(mybatis in action)之九:mybatis 代码生成工具的使用

    mybatis 应用程序,需要大量的配置文件,对于一个成百上千的数据库表来说,完全手工配置,这是一个很恐怖的工作量. 所以mybatis 官方也推出了一个mybatis代码生成工具的jar包. 今天花 ...