SammyRulez Projectz

Thoughts about Software Design, Java, geek stuff and more. All most daily

Monday, September 05, 2005

JSF: how to export UIData in Excel [ActionComponent]

Since I bore a lot of people in Apache myfaces mailing list with my newbbie questions I give this back to the word... hoping that it would be of some use for someone else.

This is my action bean that store the content of a uidata component in a excel file.

It needs POI ( v 2.0 in che classpath.

1 add the bean and the util class to your project

2 add the mappings to the faces-config.xml



ok properties meaning:

  • fileCache: where excel file are cached

  • templateFileName: excel file to use as a template: it could be an empty excel file, but it must be a valid excel 97/2000 ecc spreadsheet

  • sheet: sheet where to write data (number zero based)

  • rowOffset: row from where start writing data (number zero based)

3 add navigation .. here my example with a jsp displainig the link to the file...

<from-outcome>excel</from-outcome> <!-- excel is the outcome of my action! -->
<to-view-id>/excel.jsp</to-view-id><redirect />

4 add a command link to the footer (or header) facet of your dataTable

<f:facet name="footer">
<h:commandLink actionListener="#{excelManager.listenTable}" action="#{excelManager.exportData}" >
<f:param name="properties" value="name,password"/>
<f:param name="headers" value="Nome,Password"/>
<f:param name="filename" value="rapportino_excel.xls"/>
<h:outputText value="export in excel"/>

  • "properies" are the properties of the enclosed collection which is the value attribute of your dataTable you want to display in the column. (things like should work!)

  • "headers" are the header of each column

  • "filename" is the fixed part of the name of the output file. A time stamp and the dataTable id will be added.

I will make a consistent package if I will have the time this week with a decent "readme"

source code here and here

Thursday, September 01, 2005

Against the "Everithing sux" philosophy

I' really tired to read pseudo bile blog, without humor, of people that pretend to know almost all framework, language , Operative system, mobile device ecc.. and seem to hate them all. Why? Why do you still go into them? Change your job, your life! Why they don't buy a boat and start sealing in carabean seas... or whoatever.. The last one was this post (it is in italian but the blog's title is quite self-explaing...). This guy complain about the complexity of Java bringing the high number of modifier, default values of primitive types, 0 based count of month in Calendar as element of complexity. I find all this stuff silly, every language and every framework have its own leaks... but something you have to choose, or just STAY OUT OF THE KITCHEN IF YOU CAN'T STAND THE HEAT!