In JSF , “h:panelGrid” tag is used to generate HTML table tags to place JSF components in rows and columns layout, from left to right, top to bottom.

For example, you used to group JSF components with HTML table tags like this :

HTML

<table>
<tbody>
<tr>
<td>
Enter a number :
</td>
<td>
<h:inputText id="number" value="#{dummy.number}"
size="20" required="true"
label="Number" >
<f:convertNumber />
</h:inputText>
</td>
<td>
<h:message for="number" style="color:red" />
</td>
</tr>
</tbody>
</table>

With “h:panelGrid” tag, you can get the same table layout above, without typing any of the HTML table tags :

h:panelGrid

<h:panelGrid columns="3">

	Enter a number : 

	<h:inputText id="number" value="#{dummy.number}"
size="20" required="true"
label="Number" >
<f:convertNumber />
</h:inputText> <h:message for="number" style="color:red" /> </h:panelGrid>

Note

The “column” attribute is optional, which define the number of columns are required to lay out the JSF component, defaults to 1.

h:panelGrid example

A JSF 2.0 example to show you how to use the “h:panelGrid” tag to lay out the components properly.

1. Managed Bean

A dummy bean for demo.

package com.mkyong;

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped; @ManagedBean(name="dummy")
@SessionScoped
public class DummyBean implements Serializable{ int number; public int getNumber() {
return number;
} public void setNumber(int number) {
this.number = number;
} }

2. JSF Page

A JSF XHTML page to use “h:panelGrid” tag to places JSF components in 3 columns layout.

<?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"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"
>
<h:body> <h1>JSF 2 panelGrid example</h1> <h:form>
<h:panelGrid columns="3"> Enter a number : <h:inputText id="number" value="#{dummy.number}"
size="20" required="true"
label="Number" >
<f:convertNumber />
</h:inputText> <h:message for="number" style="color:red" /> </h:panelGrid> <h:commandButton value="Submit" action="result" /> </h:form>
</h:body>
</html>

Output following HTML result :

<?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"> <body>
<h1>JSF 2 panelGrid example</h1>
<form id="j_idt6" name="j_idt6" method="post"
action="/JavaServerFaces/faces/default.xhtml"
enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_idt6" value="j_idt6" /> <table>
<tbody>
<tr>
<td>
Enter a number :
</td>
<td>
<input id="j_idt6:number" type="text"
name="j_idt6:number" value="0" size="20" />
</td>
<td></td>
</tr>
</tbody>
</table> <input type="submit" name="j_idt6:j_idt10" value="Submit" />
<input type="hidden" .... />
</form>
</body>
</html>
  1. Demo

Screen shot of this example.

JSF 2 panelGrid example的更多相关文章

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

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

  2. JSF标签的使用2

    n  事件监听器是用于解决只影响用户界面的事件 Ø  特别地,在beans的form数据被加载和触发验证前被调用 •    用immediate=“true”指明这个行为不触发验证 Ø  在监听器调用 ...

  3. JSF 与 HTML 标签的联系

    *页面的开头 <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <%@ t ...

  4. Winter is coming Just have a little faith. JSF框架简介与实例

    JSF 体系结构: JSF 的主要优势之一就是它既是Java Web应用程序的用户界面标准又是严格遵循模型-视图-控制器 (MVC) 设计模式的框架.用户界面代码(视图)与应用程序数据和逻辑(模型)的 ...

  5. JSF2.0 タグ一覧 (h:panelGrid) 編

    JSF の HTML (UIComponent) 系タグにはテーブルを作成するタグが2種類用意されています.これらのタグと固有機能系タグを組み合わせることでテーブルを使用した画面を作成可能です. 6. ...

  6. JSFのAjaxタグのoneventでbegin/complete/successを使う

    PrimeFacesに慣れてしまって.通常のHTMLタグでの記述方法がわからなかったりする点があった…ので.メモ. Ajaxでリクエスト送信のタイミングやレスポンスが戻るタイミングに何らか(JavaS ...

  7. JSF标签大全详解

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

  8. 【转】JSF中的三大核心组件 UI标签的详细介绍和使用举例

    JSF提供了大量的UI标签来简化创建视图.这些UI标签类似于ASP.NET中的服务器组件.使用这些标签,可以通过其value,binding,action,actionListener等属性直接绑定到 ...

  9. JavaServer Faces (JSF) with Spring

    JavaServer Faces (JSF) with Spring Last modified: April 30, 2018 by baeldung Spring+ Spring MVC JSF ...

随机推荐

  1. many to one could not resolve property

    今天在做一个功能的时候 遇到了.一个Could not resolve property 的问题. 配置文件如下: <many-to-one name="user"  cla ...

  2. Kafka源码中的Producer Record定义

    1.ProducerRecord 含义: 发送给Kafka Broker的key/value 值对 2.内部数据结构: -- Topic (名字) -- PartitionID ( 可选) -- Ke ...

  3. 抛出自定义异常,spring AOP事务不回滚的解决方案

    spring AOP 默认对RuntimeException()异常或是其子类进行事务回滚,也就是说 事务回滚:throw new RuntimeException("xxxxxxxxxxx ...

  4. QCon 2015 阅读笔记 - 其他精选主题

    QCon 2015阅读笔记 QCon 2015 阅读笔记 - 移动开发最佳实践 QCon 2015 阅读笔记 - 团队建设 QCon 2015 阅读笔记 - 其他精选主题 以前分享过两个主题:移动开发 ...

  5. 【英语】Bingo口语笔记(73) - 以tly,tely结尾的误读

  6. 【自动化测试】Selenium常用的键盘事件

    send_keys(Keys.BACK_SPACE) 删除键(BackSpace)send_keys(Keys.SPACE) 空格键(Space)send_keys(Keys.TAB) 制表键(Tab ...

  7. Oracle RAC 负载均衡测试(结合服务器端与客户端)

    Oracle RAC 负载均衡使得从客户端发起的连接能够有效地分配到监听器负载较小的实例上.有两种方式实现客户端负载均衡,一是通过配置客户端的load_balance,一是通过配置服务器端的remot ...

  8. 理解javascript的caller,callee,call,apply概念

    在提到上述的概念之前,首先想说说javascript中函数的隐含参数:arguments Arguments 该对象代表正在执行的函数和调用它的函数的参数. [function.]arguments[ ...

  9. ios 页面传值4种方式(一) 之全局变量

    通用的是用代理的方式实现页面传值,但是有时候利用其它方式也可以很巧妙的解决问题,页面传值一共有4种方式: 1.使用全局变量, SharedApplication,定义一个变量来传递. 2.使用文件,或 ...

  10. SQL0668N 由于表 "db2inst1.test" 上的原因代码 "3",所以不允许操作(解因为LOAD引起的LOAD暂挂状态锁)

    DB2解因为LOAD引起的LOAD暂挂状态锁   一般解锁命名是,SET INTEGRITY FOR temp_test IMMEDIATE CHECKED   但是load暂挂状态是解不了的,可以l ...