This tag is used to create table on the page. In the columns of the table you can put any type of component like input text box, output text, command button etc.<h:column> tag is used to create column. There can be many column tags within dataTable tag. You can set header and footer in this table. For this <f:facet> tag is used. data table component and its children column component can use header and footer facet.
We can associate this table element to backing bean. So we can obtain data from this backing bean and display it on the table. Association of backing bean can also be helpful for event handling purpose. Suppose we inserted command button in columns of the table then event handling can be applied here.CSS will help you to enhance the appearance of the table's headers, footer, rows, columns.
Code Description :
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>t:dataTable example</title>
<style type="text/css">
<!--
body{
margin-top:30;
}
.TableRow1 {
background-color: #D0E6E0;
}
.TableRow2 {
background-color: #E8F7F1;
}
.TableColumn {
text-align: center
}
.TableClass {
font-family : verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 13px;
color: #000000;
padding: 2;
border-style: solid;
border-width: 2px;
}
.TableHeader {
color: #000000;
background-color: #F1F1F1;
padding: 3;
text-align: center;
border: none;
}
.TableFooter {
background-color: #F1F1F1;
}
-->
</style>
</head>
<body ><center>
<f:view>
<h:form id="form1" >
<t:dataTable id="dt1" value="#{TableBean.perInfoAll}"
var="item" bgcolor="#F1F1F1" border="10" cellpadding="5"
cellspacing="3" first="0" rows="4" width="50%" dir="LTR"
frame="hsides" rules="all"
summary="This is a JSF code to create dataTable."
rowClasses="TableRow1,TableRow2" columnClasses="TableColumn"
styleClass="TableClass" headerClass="TableHeader" footerClass="TableFooter">
<f:facet name="header">
<h:outputText value="Customer Information" />
</f:facet>
<t:column style="color:green; font-weight:bold"
headerstyle="background-color:#99CCFF;">
<f:facet name="header">
<t:outputText value="id" />
</f:facet>
<t:outputText value="#{item.id}"></t:outputText>
</t:column>
<t:column headerstyle="background-color:#99CCFF;">
<f:facet name="header">
<t:outputText value="name"/>
</f:facet>
<t:outputText value="#{item.name}"></t:outputText>
</t:column>
<t:column headerstyle="background-color:#99CCFF;">
<f:facet name="header">
<t:outputText value="phone"/>
</f:facet>
<t:outputText value="#{item.phone}"></t:outputText>
</t:column>
<t:column headerstyle="background-color:#99CCFF;">
<f:facet name="header">
<t:outputText value="city"/>
</f:facet>
<t:outputText value="#{item.city}"></t:outputText>
</t:column>
<t:column headerstyle="background-color:#99CCFF;">
<f:facet name="header">
<t:outputText value="pin"/>
</f:facet>
<t:outputText value="#{item.pin}"></t:outputText>
</t:column>
<f:facet name="footer">
<h:outputText value="The End" />
</f:facet>
</t:dataTable><br><br>
</h:form>
</f:view>
</center></body>
</html>
Rendered Output : This is the output of dataTable component.

If we set the newspaperColumns attribute to the value "2" then it shows the output like below :

Backing bean :
package net.roseindia.web.ui;
|
Html Source Code :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>t:dataTable example</title>
<style type="text/css">
<!--
body{
margin-top:30;
}
.TableRow1 {
background-color: #D0E6E0;
}
.TableRow2 {
background-color: #E8F7F1;
}
.TableColumn {
text-align: center
}
.TableClass {
font-family : verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 13px;
color: #000000;
padding: 2;
border-style: solid;
border-width: 2px;
}
.TableHeader {
color: #000000;
background-color: #F1F1F1;
padding: 3;
text-align: center;
border: none;
}
.TableFooter {
background-color: #F1F1F1;
}
-->
</style>
</head>
<body ><center>
<form id="form1" name="form1" method="post"
action="/tomahawk_tags/pages/dataTable.jsf;
jsessionid=CB7EFA115BCB8663FB81A27BD9E1C827"
enctype="application/x-www-form-urlencoded">
<table id="form1:dt1" bgcolor="#F1F1F1" border="10"
cellpadding="5" cellspacing="3" frame="hsides" rules="all"
summary="This is a JSF code to create dataTable." width="50%"
dir="LTR" class="TableClass">
<thead>
<tr><th scope="colgroup" colspan="5" class="TableHeader">
Customer Information</th></tr>
<tr><th class="TableHeader" style="background-color:#99CCFF;">
id</th>
<th class="TableHeader"
style="background-color:#99CCFF;">name</th>
<th class="TableHeader" style="background-color:#99CCFF;">
phone</th>
<th class="TableHeader" style="background-color:#99CCFF;">
city</th><th class="TableHeader"
style="background-color:#99CCFF;">pin</th>
</tr>
</thead>
<tfoot>
<tr><td colspan="5" class="TableFooter">
The End</td></tr></tfoot>
<tbody id="form1:dt1:tbody_element">
<tr class="TableRow1">
<td class="TableColumn" style="color:green;
font-weight:bold">101</td>
<td class="TableColumn">CHANDAN</td>
<td class="TableColumn">9891444444</td>
<td class="TableColumn">Delhi</td>
<td class="TableColumn">111111</td>
</tr>
<tr class="TableRow2">
<td class="TableColumn"
style="color:green;font-weight:bold">102</td>
<td class="TableColumn">RAVI</td>
<td class="TableColumn">9911666666</td>
<td class="TableColumn">Bombay</td>
<td class="TableColumn">222222</td>
</tr>
<tr class="TableRow1">
<td class="TableColumn"
style="color:green; font-weight:bold">103</td>
<td class="TableColumn">JOHN</td>
<td class="TableColumn">9313888888</td>
<td class="TableColumn">New York</td>
<td class="TableColumn">333333</td>
</tr>
<tr class="TableRow2">
<td class="TableColumn"
style="color:green; font-weight:bold">104</td>
<td class="TableColumn">ANDREW</td>
<td class="TableColumn">9911222222</td>
<td class="TableColumn">Florida</td>
<td class="TableColumn">444444</td>
</tr>
</tbody>
</table>
<br><br>
<input type="hidden" name="form1_SUBMIT" value="1" />
<input type="hidden" name="javax.faces.ViewState"
id="javax.faces.ViewState"
value="rO0ABXVyABNbTGphdmEubGFuZy5PYmplY3Q7kM5YnxBzKWwCAAB4cAAAAAN0A
AExcHQAFC9wYWdlcy9kYXRhVGFibGUuanNw" /></form>
</center><!-- MYFACES JAVASCRIPT -->
</body>
</html>
|
This tag contains attributes given below :
- none No side, Default Value
- above Top side only
- below Bottom side only
- hsides Top and bottom sides only
- vsides Right and left sides only
- lhs Left hand side only
- rhs Right hand side only
- box All four sides
- border All four sides
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Tomahawk dataTable tag View All Comments
Post your Comment