The cellSetTable Facelet tag

Friday, November 25, 2011

This tag renders an org.olap4j.CellSet instance. It mimics someway the behavior of <h:dataTable>: provides the main structure for displaying the CellSet and allows
the page designer to specify the contents for each part of the table.

The tag’s structure is as follows:

<olap:cellSet value=”…” var=”cell”>

<olap:columnAxis>

<f:facet
name=”header”>

<!—

This content
is rendered in the headers

of the column axis dimensions

-->

</f:facet>

<!—

This content is rendered in the members

of the column axis dimensions

-->

</olap:columnAxis>

<olap:rowAxis>

<f:facet
name=”header”>

<!—

This content
is rendered in the headers

of the row axis dimensions

-->

</f:facet>

<!—

This content is rendered in the members

of the row axis dimensions

-->

</olap:columnAxis>

<olap:dataCell>

<!—

This content is rendered in the cells

of the CellSet

-->

</olap:dataCell>

</olap:cellSet>

This markup would produce the following
HTML table, where the background color of the cell identifies the markup piece
used to generate its content

Region

USA

Canada

Measures

Gender

Promotions

Unit Sales

Store Cost

Unit Sales

StoreCost

Male

TV Spot

0

0

0

0

Newspaper Ad

0

0

0

0

Female

TV Spot

0

0

0

0

Newspaper Ad

0

0

0

0

The var attribute in the cellSetTable tag
allows the page to use its value as a variable in EL expressions used within
the children of the cellSetTable. This variable will refer to an instance of the CellSetItemInfo interface
defined as follows:

interface CellSetItemInfo {

public
Hierarchy getHierarchy();

public
Member getMember();

public
List<Member> getPosition();

public Cell getData()

public Axis getAxis();

}

The following table shows, for each
property of this instance, he areas of the table where such a property is
non-null

axis

hierarchy

position

member

cell

The code below shows a simple example for a
<olap:cellSetTable>

<olap:cellSetTable value=”#{olapSample.cellSet}”
var=”cell”>

<olap:columnAxis>

<f:facet name=”header>

<h:outputText value=”#{cell.hierarchy.caption}”/>

</f:facet>

<h:outputText value=”#{cell.member.caption}”/>

</olap:columnAxis>

<olap:rowAxis>

<f:facet name=”header>

<h:outputText value=”#{cell.hierarchy.caption}”/>

</f:facet>

<h:outputText value=”#{cell.member.caption}”/>

</olap:rowAxis>

<olap:dataCell>

<h:outputText value=”#{cell.data.formattedValue}”/>

</olap:dataCell>

</olap:cellSetTable>

The managed bean providing the CellSet would
have the following structure.

I use a RequestScoped in combination with @PostConstruct
and @PreDestroy
methods to open a connection to the olap4j server before any use of the bean,
and close that connection once the request process lifecycle has ended.

In a real-world example the connection can
be retrieved lazily, and we can store the resulting CellSet in a field to avoid
executing the same query several times within the same request.