JSF Tables

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

JSF TABLES

DATA TABLE TAG

 h:dataTable
<h:dataTable value=“#{store.categoryLarge.dogs}” var=„largeDog‟>
<h:column>
<h:outputText value=“#{largeDog.name}”/>
</h:column>
<h:column>
<h:outputText value=“#{largeDog.age}”/>
</h:column>
</h:dataTable>

• value attribute must correspond to a Java


object, array, java.util.List,
java.sql.ResultSet, or a
javax.faces.model.DataModel
HEADERS, FOOTERS, AND CAPTIONS
<h:dataTable value=“#{store.categoryLarge.dogs} var=„largeDog‟>
<f:facet name=“caption”>
<h:outputText value=“#{msgs.AVAILABLE_LARGE_DOGS”/>
</f:facet>
<h:column>
<f:facet name=“header”>
<h:panelGrid> To place multiple
<h:outputText value=“#{msgs.DOG}”/> components in a header
<h:outputText value=“#{msgs.NAME}”/>
or a footer you must
</h:panelGrid>
</f:facet> group them using a
<h:outputText value=“#{largeDog.name}”/> panelGrid or panelGroup
<f:facet name=“footer”>
<h:outputText value=“[alpha]”/>
</f:facet>
</h:column>
</h:dataTable>
EDITING TABLES

 Any JSF Component can be placed in a cell


<h:dataTable value=“#{store.categoryLarge.dogs} var=„largeDog‟>
<h:column>
<f:facet name=“header”>
<h:outputText value=“#{msgs.EDIT_COLUMN”/>
</f:facet>
<h:selectBooleanCheckbox value=“#{dog.editable}”/>
</h:column>
<h:column>
<h:outputText value=“#{largeDog.name}”/>
</h:column>
<h:column>
<h:inputText value=“#{largeDog.price}” rendered=“#{dog.editable}”
size=“10”/>
<h:outputText value=“#{largeDog.price}” rendered=“#{not
dog.editable}”/>
</h:column>
</h:dataTable>
ADDING A SCROLLBAR TO A TABLE

<div style=“overflow:auto; width:100%;


height=200px;”>
<h:dataTable…>

</h:dataTable>
</div>
STYLING A TABLE
<h:dataTable value=“#{store.categoryLargeDogs.dog}” var=“dog”
styleClass=“tableStyle” headerClass=“headerStyle”
columnClasses=“oddColumn,evenColumn”>
.tableStyle { .oddColumn {
border: thin solid black; text-align: center;
} background: #002255;
.headerStyle {
text-align: center; }
font-style: italic; .evenColumn{
color: #002255; text-align: center;
background: #223300; background: #223300;
} }
JSF TABLE MODELS

 The JSF Table models wrap Java objects like,


arrays, lists, and result sets that represent
table data
javax.faces.model.TableModel

Inheritance

javax.faces.model.ArrayDataModel javax.faces.model.ListDataModel

Composition

java.util.Array java.util.ArrayList
DELETING OR ADDING TABLE ROWS

 Two methods of the tableModel superclass


should be used:
 getWrappedData();

 setWrappedData();

 JSF Table Models should be subclassed so that


the model remains independent of the view
implementation
DECORATOR PATTERN

ListDataModel

Inheritance
DataModel
<<Interface>>

LineItemSortFilterModelModelJSF
DECORATOR PATTERN MOTIVATION

 Works by wrapping the new "decorator" object


around the original object, which is typically
achieved by passing the original object as a
parameter to the constructor of the decorator, with
the decorator implementing the new functionality.
 Interface of the original object is maintained by
the decorator.
 Motivation: Provides a method of keeping our
model independent of the view implementation
ABSTRACT FACTORY PATTERN

ViewFactory Shopping Cart

DataModel
<<Interface>>

ViewFactoryJSF LineItemSortFilterModelJSF
ABSTRACT FACTORY PATTERN CONTINUED…

 The factory determines the actual concrete type of object to be created, and
it is here that the object is actually created. However, the factory only
returns an abstract pointer to the created concrete object.
 Insulates model from object creation by having the model ask a factory
object to create an object of the desired abstract type and to return an
abstract pointer to the object.
 Model code does not know - and is not burdened by - the actual concrete
type of the object which was just created. However, the type of a concrete
object (and hence a concrete factory) has been known to the abstract
factory, for instance, factory can read it from a configuration file.
 Model code has no knowledge whatsoever of the concrete type, Model
code accesses such objects only through their abstract interface.
 Adding new concrete types is done by modifying the code to use a
different factory, a modification which is typically one line in one file.

You might also like