I still cannot reiterate enough, how much Seam is productive in developing rich web mvc apps. Take for example, a very common requirement where a rich datatable is present and users would want a “export to excel” functionality right next to each of these tables. With Seam, this is as simple as one line of facelets tag
<h:commandLink
action="#{org.jboss.seam.excel.excelExporter.export('form:dataTable')}">
<h:graphicImage value="/img/excel.gif" />
</h:commandLink>
where form is the form id and ‘datatable’ is the id of the datatable in that form. Thats as simple as it can get! If you want a customized excel, then writing the excel layout, formatting by hand does not use java code at all! Everything can be coded on plain facelet tags. To demonstrate how easy it is, to create excel spreadsheets on the fly, look at this example
<e:workbook type="jxl" xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:e="http://jboss.com/products/seam/excel"
xmlns:f="http://java.sun.com/jsf/core"
autoFilterDisabled="false">
<e:cellTemplate name="cellStyles">
<e:background color="gray_25" pattern="solid"/>
<e:font fontName="Lucida Grande" bold="true"/>
</e:cellTemplate>
<e:worksheet name="Search Criteria" value="#{searchCriteriaList}" var="criteria">
<e:column autoSize="true">
<f:facet name="header">
<e:cell value="Time Period" templates="cellStyles"/>
</f:facet>
<e:cell value="#{criteria.timePeriod}" />
</e:column>
<e:column autoSize="true">
<f:facet name="header">
<e:cell value="Foo name" templates="cellStyles"/>
</f:facet>
<e:cell value="#{criteria.foo.name}" />
</e:column>
<e:column autoSize="true">
<f:facet name="header">
<e:cell value="Bar Name" templates="cellStyles"/>
</f:facet>
<e:cell value="#{criteria.bar.name}"/>
</e:column>
</e:worksheet>
<e:worksheet name="Matrix" value="#{searchResults}" var="res" headerMargin="5"
verticalFreeze="1" selected="true" showGridLines="true" topMargin="5">
<e:column autoSize="true">
<f:facet name="header">
<e:cell value="FooName" templates="cellStyles"/>
</f:facet>
<e:cell value="#{res.foo.name}" />
</e:column>
<e:column autoSize="true">
<f:facet name="header">
<e:cell value="Bar name" templates="cellStyles"/>
</f:facet>
<e:cell value="#{res.bar.name}"/>
</e:column>
</e:worksheet>
</e:workbook>
The syntax is so simple, even a layman can understand. As you’ve seen, I’ve created two worksheets, the first one displaying the search criteria and the second one displaying the results (List
The Seam-excel support is built in the 2.1 beta release
2 Comments
Note that the styling/cellTemplate had a large overhaul between BETA1 and GA. It is now CSS-based. Refer to the 2.1.0GA manual for the details.
Please I need a working example, please….
Post a Comment