Developing Web 2.0 applications
with JavaServerFaces
and Dreamweaver
>> Just Became Easier
Documentation
Search
  1. Introduction
  2. Getting Started
  3. Developing Web Sites
  4. Using Components
  5. Internationalization
  6. Code View Support
  7. Design View Support
  8. Keyboard Shortcuts
  9. Tag Object Toolbars
  10. JSF Server Behaviors
  11. Property Inspectors
  12. JSF Tag Reference
JSF HTML Tag Library
  h:body
  h:button
  h:column
  h:commandButton
  h:commandLink
  h:dataTable
  h:form
  h:graphicImage
  h:head
  h:inputHidden
  h:inputSecret
  h:inputText
  h:inputTextarea
  h:link
  h:message
  h:messages
  h:outputFormat
  h:outputLabel
  h:outputLink
  h:outputScript
  h:outputStylesheet
  h:outputText
Selected h:panelGrid
  h:panelGroup
  h:selectBooleanCheckbox
  h:selectManyCheckbox
  h:selectManyListbox
  h:selectManyMenu
  h:selectOneListbox
  h:selectOneMenu
  h:selectOneRadio
If you like this documentation, please take a look at my book:

12. JSF HTML Tag Reference

Documentation > JSF > JSF Tag Reference > JSF HTML Tag Library > h:panelGrid

h:panelGrid

The h:panelGrid tag renders an HTML4 compliant table element. The h:panelGrid component can be used as a layout manager for a grid-based user interface. It simplifies the task of constructing a layout table to hold form fields, labels, and buttons. The h:panelGrid component, like the h:dataTable component, can be customized extensively using Cascading Style Sheets (CSS). The h:panelGrid does not use an underlying data model to provide rows of data for rendering purposes. Rather, this component is a layout container that renders other JSF components in a grid of rows and columns. By default, a h:panelGrid component has only one column.

You can specify how many columns are used to display the components, and the h:panelGrid component determines how many rows are needed at rendering time. For example, if you set the number of columns for your panelGrid to 2 and you include 4 components inside it, the rendered table will have two rows with two columns ("td" cells) in each row. The layout algorithm for the child components of a h:panelGrid is as follows. The components are laid out one at a time, from left to right and from top to bottom, starting with the first component and ending with the last component in the order in which the appear inside the h:panelGrid tag.

This component renders one component per column and keeps track of how many columns it has rendered. When the number of columns rendered for a particular row is the same as the value of the "columns" attribute, it starts a new row and continues in this manner until there are no more components to render. If you want to combine several components into a single column, you can use a h:panelGroup component. The h:panelGroup component renders its children but still counts as one component. This is useful for cases where a component only allows one child component, such as the facet tag and the column layout algorithm described above. You can also define header and a footer facets for the h:panelGrid.

These are rendered as a single "th" element in a row at the top of the table and as a single "td" element in a row at the bottom of the table.

JSF Example

<!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:f="http://java.sun.com/jsf/core" 
      xmlns:h="http://java.sun.com/jsf/html">
<h:head />
<body>
<h:form id="form">
	<h:panelGrid id="panel" columns="2" border="1" cellpadding="0" cellspacing="2">
		<f:facet name="header">
			<h:outputText value="#{messages.signInMessage}"/>
		</f:facet>
		<h:outputLabel for="username" value="#{messages.usernameLabel}" />
		<h:inputText id="username" value="#{userController.user.username}" />
		<h:outputLabel for="password" value="#{messages.passwordLabel}" />
		<h:inputText id="password" value="#{userController.user.password}" />
		<f:facet name="footer">
			<h:panelGroup style="display:block; text-align:center">
				<h:commandButton id="submit" value="#{messages.submitLabel}" />
			</h:panelGroup>
		</f:facet>
	</h:panelGrid>
</h:form>
</body>
</html>
This example was formatted by JSFToolbox for Dreamweaver.

com/mycompany/messages.properties

usernameLabel=Username
passwordLabel=Password
signInMessage=Please sign in
submitLabel=Submit

faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
	version="2.0">
	<application>
		<resource-bundle>
			<base-name>com.mycompany.messages</base-name>
			<var>messages</var>
		</resource-bundle>
	</application>
</faces-config>

Rendered Output

Rendered h:panelGrid tag

HTML Output

<table border="1" cellpadding="0" cellspacing="2">
  <thead>
    <tr>
      <th colspan="2" scope="colgroup">Please sign in</th></tr>
  </thead>
  <tfoot>
    <tr>
      <td colspan="2">
        <span style="display:block; text-align:center">
          <input id="form:submit" type="submit" name="form:submit" value="Submit" />
        </span>
      </td>
    </tr>
  </tfoot>
  <tbody>
    <tr>
      <td><label for="form:username">Username</label></td>
      <td><input id="form:username" type="text" name="j_idt10:username" /></td>
    </tr>
    <tr>
      <td><label for="form:password">Password</label></td>
      <td><input id="form:password" type="text" name="form:password" /></td>
    </tr>
  </tbody>
</table>

Tag Attributes

bgcolor Text
 
The bgcolor attribute sets the background color for the table. This value can be the name or the hexadecimal value of the color.
binding Expression
 
The value-binding expression linking this component tag to a backing bean property.
bodyrows Text
 
Comma separated list of row indices for which a new "tbody" element should be started (and any previously opened one should be ended).
border Text
 
The border attribute sets the pixel width of the border to be drawn around the table.
captionClass Text
 
Space-separated list of CSS style class(es) that will be applied to any caption generated for this table.
captionStyle Text
 
CSS style(s) to be applied when this caption is rendered.
cellpadding Text
 
The cellpadding attribute sets the width between the border of each cell and its contents.
cellspacing Text
 
The cellspacing attribute sets the width of the space between the outside and inside edges of the table as well as the space between cells.
columnClasses Text
 
The columnClasses attribute accepts a comma-delimited list of CSS style classes that will be applied to the columns of the table. Style classes for an individual column may also be defined in a space separated list. A style class is applied to a table column as the value for the class attribute of rendered td or th element. The algorithm used to apply the CSS style classes to the table columns is simple. In the table rendering process, style classes are applied to columns one at a time until (a) there are no more columns to display or (b) there are no more style classes to apply.
  • If (a) happens at the same time as (b), the next row in the table is rendered.
  • If (a) happens before (b), the remaining style classes are ignored.
  • If (b) happens before (a), the remaining columns will not have style classes.
columns Text
 
The columns attribute sets the number of columns to render before starting a new row.
dir Enumerated
 
The dir attribute is a standard HTML attribute that overrides the default text directionality for this component. The values accepted for this component are "LTR" (left-to-right) and "RTL" (right-to-left).

This attribute accepts the following values:

  • LTR
  • RTL
footerClass Text
 
The footerClass attribute accepts a space-separated list of CSS style classes (or simply a style class) to be applied to the table footer if one has been defined.
frame Text
 
The frame attribute sets the code specifying which sides of the frame around this table will be visible. The valid values for this attribute are:
  • none (no sides, 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) and
  • border (all four sides)

This attribute accepts the following values:

  • above
  • below
  • border
  • box
  • hsides
  • lhs
  • none
  • rhs
  • vsides
headerClass Text
 
The headerClass attribute accepts a space-separated list of CSS style classes (or a single style class) to be applied to any header generated for this table.
id Text
 
The unique identifier value for this component. The value must be unique within the closest naming container.
lang Text
 
The lang attribute is a standard HTML attribute that sets the code describing the language to be used in the markup generated by this component.
onclick Text
 
The onclick attribute sets the JavaScript code to execute when the mouse pointer is clicked over this element.
ondblclick Text
 
The ondblclick attribute sets the JavaScript code to execute when the mouse pointer is double-clicked over this element.
onkeydown Text
 
The onkeydown attribute sets the JavaScript code to execute when a key is pressed down over this element.
onkeypress Text
 
The onkeypress attribute sets the JavaScript code to execute when a key is pressed and released over this element.
onkeyup Text
 
The onkeyup attribute sets the JavaScript code to execute when a key is released over this element.
onmousedown Text
 
The onmousedown attribute sets the JavaScript code to execute when the mouse pointer is pressed down over this element.
onmousemove Text
 
The onmousemove attribute sets the JavaScript code to execute when the mouse pointer is moved within this element.
onmouseout Text
 
The onmouseout attribute sets the JavaScript code to execute when the mouse pointer is moved away from this element.
onmouseover Text
 
The onmouseover attribute sets the JavaScript code to execute when the mouse pointer is moved onto this element.
onmouseup Text
 
The onmouseup attribute sets the JavaScript code to execute when the mouse button is released over this element.
rendered Boolean
 
A value-binding expression that evaluates to a Boolean condition indicating if this component should be rendered.
rowClasses Text
 
The rowClasses attribute accepts a comma-delimited list of CSS style classes to be applied to the rows of the table. Style classes for an individual row may also be defined in a space separated list. A style class is applied to a table row as the value for the class attribute of rendered tr element. Style classes are applied to rows in the same order that they are defined. For example, if there are two style classes, the first is applied to the first row, the second is applied to the second row, the first is applied to the third row, the second is applied to the fourth row, and so on. The list of styles is looped over from the beginning until there are no more rows to display.
rules Text
 
The rules attribute specifies which lines will appear between cells in the table. The valid values for this attribute are:
  • none (no rules, default value)
  • groups (between row groups)
  • rows (between rows only)
  • cols (between columns only)
  • and all (between all rows and columns)
style Text
 
The style attribute sets the CSS style definition to be applied to this component when it is rendered.
styleClass Text
 
The styleClass attribute sets the CSS class to apply to this component when it is rendered.
summary Text
 
The summary attribute describes the purpose and structure of the table for accessibility support for assistive devices and non-visual user agents.
title Text
 
The title attribute is a standard HTML attribute that sets the tooltip text to display for the rendered component.
width Text
 
Width of the entire table, for visual user agents.