jsf tables

12
JSF TABLES

Upload: negriz

Post on 28-Mar-2015

146 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: jsf tables

JSF TABLES

Page 2: 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

Page 3: jsf tables

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

Page 4: jsf tables

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>

Page 5: jsf tables

ADDING A SCROLLBAR TO A TABLE

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

height=200px;”>

<h:dataTable…>

</h:dataTable>

</div>

Page 6: jsf tables

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;

}

Page 7: jsf tables

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

Page 8: jsf tables

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

Page 9: jsf tables

DECORATOR PATTERN

LineItemSortFilterModelModelJSF

DataModel

<<Interface>>

ListDataModel

Inheritance

Page 10: jsf tables

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

Page 11: jsf tables

ABSTRACT FACTORY PATTERN

ViewFactory

ViewFactoryJSF LineItemSortFilterModelJSF

Shopping Cart

DataModel

<<Interface>>

Page 12: jsf tables

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.