jsf tables
Transcript of jsf tables
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>
<h:outputText value=“#{msgs.DOG}”/>
<h:outputText value=“#{msgs.NAME}”/>
</h:panelGrid>
</f:facet>
<h:outputText value=“#{largeDog.name}”/>
<f:facet name=“footer”>
<h:outputText value=“[alpha]”/>
</f:facet>
</h:column>
</h:dataTable>
To place multiple
components in a header
or a footer you must
group them using a
panelGrid or panelGroup
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 {
border: thin solid black;
}
.headerStyle {
text-align: center;
font-style: italic;
color: #002255;
background: #223300;
}
.oddColumn {
text-align: center;
background: #002255;
}
.evenColumn{
text-align: center;
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
javax.faces.model.ArrayDataModel
java.util.Array
Inheritance
Composition
javax.faces.model.ListDataModel
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
LineItemSortFilterModelModelJSF
DataModel
<<Interface>>
ListDataModel
Inheritance
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
ViewFactoryJSF LineItemSortFilterModelJSF
Shopping Cart
DataModel
<<Interface>>
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.