2008-02-20
JSF h:dataTable 标签用法
<html>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<f:view>
<head>
<title><h:outputText value="#{msgs.windowTitle}" /></title>
</head>
<body>
<h:outputText value="#{msgs.pageTitle}" />
<p>
<h:form>
<h:dataTable value="#{tableData.names}" var="name">
<h:column>
<h:outputText value="#{name.last} " />
</h:column>
<h:column>
<h:outputText value="#{name.first}" />
</h:column>
</h:dataTable>
</h:form>
</body>
</f:view>
</html>
Listing 5–2 simple/src/java/com/corejsf/Name.java
1. package com.corejsf;
2.
3. public class Name {
4. private String first;
5. private String last;
6.
7. public Name(String first, String last) {
8. this.first = first;
9. this.last = last;
10. }
12. public void setFirst(String newValue) { first
13. public String getFirst() { return first; }
14.
15. public void setLast(String newValue) { last
16. public String getLast() { return last; }
17. }
Listing 5–3 simple/src/java/com/corejsf/TableData.
1. package com.corejsf;
2.
3. public class TableData {
4. private static final Name[] names = new Name[]
5. new Name("William", "Dupont"),
6. new Name("Anna", "Keeney"),
7. new Name("Mariko", "Randor"),
8. new Name("John", "Wilson")
9. };
10.
11. public Name[] getNames() { return names;}
12. }
NOTE:
The value attribute represents the data over which h:dataTable iterates; that data
must be one of the following:
• A Java object
• An array
• An instance of java.util.List
• An instance of java.sql.ResultSet
• An instance of javax.servlet.jsp.jstl.sql.Result
• An instance of javax.faces.model.DataModel
//////////////////////////////////////////////////////////////////////
下面在页眉和页脚的<html>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<f:view>
<head>
<link href="styles.css" rel="stylesheet" type="text/css" />
<title><h:outputText value="#{msgs.windowTitle}" /></title>
</head>
<body>
<h:form>
<h:dataTable value="#{tableData.names}" var="name"
captionStyle="font-size: 0.95em; font-style:italic"
style="width: 250px;">
<f:facet name="caption">
<h:outputText value="An array of names:" />
</f:facet>
<h:column headerClass="columnHeader" footerClass="columnFooter">
<f:facet name="header">
<h:outputText value="#{msgs.lastnameColumn}" />
</f:facet>
<h:outputText value="#{name.last}" />
<f:facet name="footer">
<h:outputText value="#{msgs.alphanumeric}" />
</f:facet>
</h:column>
<h:column headerClass="columnHeader" footerClass="columnFooter">
<f:facet name="header">
<h:outputText value="#{msgs.firstnameColumn}" />
</f:facet>
<h:outputText value="#{name.first}" />
<f:facet name="footer">
<h:outputText value="#{msgs.alphanumeric}" />
</f:facet>
</h:column>
</h:dataTable>
</h:form>
</body>
</f:view>
</html>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<f:view>
<head>
<title><h:outputText value="#{msgs.windowTitle}" /></title>
</head>
<body>
<h:outputText value="#{msgs.pageTitle}" />
<p>
<h:form>
<h:dataTable value="#{tableData.names}" var="name">
<h:column>
<h:outputText value="#{name.last} " />
</h:column>
<h:column>
<h:outputText value="#{name.first}" />
</h:column>
</h:dataTable>
</h:form>
</body>
</f:view>
</html>
Listing 5–2 simple/src/java/com/corejsf/Name.java
1. package com.corejsf;
2.
3. public class Name {
4. private String first;
5. private String last;
6.
7. public Name(String first, String last) {
8. this.first = first;
9. this.last = last;
10. }
12. public void setFirst(String newValue) { first
13. public String getFirst() { return first; }
14.
15. public void setLast(String newValue) { last
16. public String getLast() { return last; }
17. }
Listing 5–3 simple/src/java/com/corejsf/TableData.
1. package com.corejsf;
2.
3. public class TableData {
4. private static final Name[] names = new Name[]
5. new Name("William", "Dupont"),
6. new Name("Anna", "Keeney"),
7. new Name("Mariko", "Randor"),
8. new Name("John", "Wilson")
9. };
10.
11. public Name[] getNames() { return names;}
12. }
NOTE:
The value attribute represents the data over which h:dataTable iterates; that data
must be one of the following:
• A Java object
• An array
• An instance of java.util.List
• An instance of java.sql.ResultSet
• An instance of javax.servlet.jsp.jstl.sql.Result
• An instance of javax.faces.model.DataModel
//////////////////////////////////////////////////////////////////////
下面在页眉和页脚的<html>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<f:view>
<head>
<link href="styles.css" rel="stylesheet" type="text/css" />
<title><h:outputText value="#{msgs.windowTitle}" /></title>
</head>
<body>
<h:form>
<h:dataTable value="#{tableData.names}" var="name"
captionStyle="font-size: 0.95em; font-style:italic"
style="width: 250px;">
<f:facet name="caption">
<h:outputText value="An array of names:" />
</f:facet>
<h:column headerClass="columnHeader" footerClass="columnFooter">
<f:facet name="header">
<h:outputText value="#{msgs.lastnameColumn}" />
</f:facet>
<h:outputText value="#{name.last}" />
<f:facet name="footer">
<h:outputText value="#{msgs.alphanumeric}" />
</f:facet>
</h:column>
<h:column headerClass="columnHeader" footerClass="columnFooter">
<f:facet name="header">
<h:outputText value="#{msgs.firstnameColumn}" />
</f:facet>
<h:outputText value="#{name.first}" />
<f:facet name="footer">
<h:outputText value="#{msgs.alphanumeric}" />
</f:facet>
</h:column>
</h:dataTable>
</h:form>
</body>
</f:view>
</html>
发表评论
- 浏览: 10232 次
- 性别:

- 来自: 合肥

- 详细资料
搜索本博客
我的相册
SL372068
共 7 张
共 7 张
最近加入圈子
链接
最新评论
-
晚上思考人生千条路,白天 ...
一夜思量千条路,明朝依旧卖豆芽。呵呵!同感!
-- by pure -
晚上思考人生千条路,白天 ...
同感~~
-- by hanssonlan -
成功人需要的三要素
成功是个过程。一路上有很多的汗水和泪水。
-- by xiaozmn -
勒紧裤腰带 买了两百书
无语。上当被耍!
-- by bruce.peng -
JBPM JPA Spring 闹别 ...
如何保证事务?我觉得事务是最大的问题.
-- by fuwang






评论排行榜