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

JSF tag…

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

Render this HTML code…

  1. <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”.

  1. package com.mkyong.form;
  2. import javax.faces.bean.ManagedBean;
  3. import javax.faces.bean.SessionScoped;
  4. import java.io.Serializable;
  5. @ManagedBean(name="user")
  6. @SessionScoped
  7. public class UserBean implements Serializable {
  8. private String address;
  9. public String getAddress() {
  10. return address;
  11. }
  12. public void setAddress(String address) {
  13. this.address = address;
  14. }
  15. }

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”.

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml"
  5. xmlns:h="http://java.sun.com/jsf/html">
  6. <h:body>
  7. <h1>JSF 2 textarea example</h1>
  8. <h:form>
  9. <table>
  10. <tr>
  11. <td valign="top">Address :</td>
  12. <td><h:inputTextarea value="#{user.address}" cols="30" rows="10" /></td>
  13. </tr>
  14. </table>
  15. <h:commandButton value="Submit" action="user" />
  16. </h:form>
  17. </h:body>
  18. </html>

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

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml"
  5. xmlns:h="http://java.sun.com/jsf/html">
  6. <h:body>
  7. <h1>JSF 2 textarea example</h1>
  8. Address : <h:outputText value="#{user.address}" />
  9. </h:body>
  10. </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. HBase学习笔记

    关键类: HBaseAdmin 管理Hbase的,主要负责DDL操作 HTable 管理表中数据,主要负责DML操作 1.为了避免热点,更多的建表方法 在Shell中: },{SPLITS=>[ ...

  2. Codeforces Round #273 (Div. 2)

    A. Initial Bet 题意:给出5个数,判断它们的和是否为5的倍数,注意和为0的情况 #include<iostream> #include<cstdio> #incl ...

  3. REVOKE DBA权限要小心

      REVOKE DBA权限要小心 转载:http://blog.csdn.net/lwei_998/article/details/6133557 发现某些用户有DBA权限的时候,为了安全,一般我们 ...

  4. EF 更新指定的字段

    假如你有个表,有30个字段,你只想更新其中的1到2个字段的话,就可以用得上这篇文章 作用:类似于我们以前的sql代码 update xxx表 set name='ok',pwd='ok' where ...

  5. python模拟http请求

    下文主要讲述如何利用python自带的库模拟http请求,为以后利用python做API测试做准备. 只讲述模拟http的过程,具体到自己用的时候,要以自己的应用为准做出适当的调整. #!coding ...

  6. JavaScript学习笔记(备忘录)

    ===运算符 判断数值和类型是否相等.如: console.log('s'==='s') //输出trueconsole.log('1'===1) //输出false

  7. 安装服务Memcached+Nginx+Php linux下安装

    Memcached安装 1.      源码安装libevent(下载地址:http://monkey.org/~provos/libevent/) 2.      源码安装memcached(下载地 ...

  8. 【DFS,双向】NYOJ-20-吝啬的国度

    [题目链接:NYOJ-20] 很巧妙,要好好想想 #include <iostream> #include <stdio.h> #include <vector> ...

  9. 【转】那些不能错过的Xcode插件 -- 不错不错

    原文网址:http://www.cocoachina.com/industry/20130918/7022.html 古人云“工欲善其事必先利其器”,打造一个强大的开发环境,是立即提升自身战斗力的绝佳 ...

  10. MySQL基础之第8章 视图

    8.1.视图简介 视图由数据库中的一个表,视图或多个表,视图导出的虚拟表.其作用是方便用户对数据的操作. 8.2.创建视图必须要有CREATE VIEW 和 SELECT 权限SELECT selec ...