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 (http://jakarta.apache.org/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

<managed-bean>
<managed-bean-name>excelManager</managed-bean-name>
<managed-bean-class>com.kyub.jsf.excelaction.ExcelManagerBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property><property-name>fileCache</property-name>
<value>/Users/sammyrulez/IdeaProjects/Faces/exploded/</value>
</managed-property><managed-property>
<property-name>templateFileName</property-name>
<value>/Users/sammyrulez/IdeaProjects/Faces/workbook.xls</value>
</managed-property>
<managed-property>
<property-name>sheet</property-name>
<value>0</value>
</managed-property>
<managed-property>
<property-name>rowOffset</property-name>
<value>3</value>
</managed-property>


</managed-bean>

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...

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

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"/>
</h:commandLink>
</f:facet>


  • "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 order.customer.name 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 http://www.kyub.com/ExcelManagerBean.java and here http://www.kyub.com/ReflectionUtil.java

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!

Tuesday, May 24, 2005

Linuxworld expo

Agai I got my day at LinuxWorld Italy. I will take may speach in the afternnoon. Everyting ins massy as usual, good people and goot stuff. I'm really impressed form the quality of the gadgets.. :-)
In my agenda I have:

  • Linux on Fedora
  • Find someone from Sun to talk about Path Finder
  • Find some PHP Geek to argue with
  • Find a novell expert thath explain me hoe to mount a Novell Fileserver on my Fedora core 3

Monday, May 16, 2005

Richard Stallman letter to Italian Parliament about sw patents

This is a letter that Richard Stallman sent to the Italian Parliament. We have big problems with the upcoming software patent laws and such a big voice could help. I hope it will help. I will post an english version soon

Lettera Aperta di Richard Stallman al Parlamento Italiano — Fellowship:
Cari membri del Parlamento italiano,

Gli sviluppatori e gli utilizzatori di software in Europa si troveranno di fronte ad un grande pericolo se l'UE permetter�di brevettare le tecniche di software: il pericolo di essere incriminati per le idee contenute nei software che essi sviluppano e usano.

A differenza del copyright, che protegge la descrizione dell'intero programma ma non le singole idee che lo compongono, la brevettabilit�del software consentirebbe un monopolio sull'uso di tecniche generiche. Un programma complesso �la combinazione di migliaia di queste tecniche. Se un paese permette la brevettabilit�di ognuna di queste tecniche, un programma complesso pu�infrangere centinaia di brevetti in un colpo solo. ( secondo uno studio svolto lo scorso anno il Kernel di Linux, la parte centrale del programma linux, usato per il sistema operativo GNU, infrangerebbe 283 brevetti USA)

Come sono queste tecniche? Consideriamo la 'progress bar', la barra progressiva che gradualmente passa dallo 0% al 100% mostrando sullo schermo la realizzazione di una operazione, come l'apertura di una pagina web o lo scaricamento di un documento. Questa tecnica �una piccola parte contenuta in migliaia di programmi software che svolgono differenti funzioni. Persino questa tecnica �stata brevettata all'Ufficio Europeo dei Brevetti, insieme ad altre 50.000, a dispetto dello stesso trattato costitutivo dell'Ufficio Europeo dei Brevetti. Se la Direttiva del Unione Europea desse un valore legale a questi brevetti, gli sviluppatori e gli utilizzatori di migliaia di programmi rischierebbero la minaccia di incriminazioni.

Un programma �come un romanzo: una raccolta di dettagli che insieme sviluppano molte idee. Immaginate cosa accadrebbe se ogni idea letteraria venisse brevettata, per esempio 'una scena d'amore con una donna sul balcone' o 'gli occhi blu di una persona che assomigliano al mare'.

Tuesday, April 26, 2005

JavaBlackBelt - knoked down!

JavaBlackBelt - Java skills evaluation platform:
"a few hours ago and we've got between 500 and 1000 concurrent users. It looks like it cannot stand such mass and the server crashed twice in 4 hours.
Sorry if it crashed (or will crash) in the middle of your quizz.
Expect problems during the next 24h.
Thank you for your patience!"



Well beeing a Karate black I shoud say that scalability is not in their Kata portfolio. I'm realizing that scalability is everithig in web-apps.
Here an example: my customer ask me to build an application to manage 100 object. At the end of the test he said the "real world" model has about 2000 object... so I fear that tasting should focus more on scalablity, having a sort of grain of scale performance graph to be sure how to manage growth.

Wednesday, March 02, 2005

Flickr for files

It would be great to have the same service as Flickr for files , mainly short clips, PDF, keynotes.. I mean a selective collection of file types with an uploader, metadata, tags and API to manage them... Well this is my daily wish.. :-) If you know a similar service drop a comment please!

Monday, February 28, 2005

IBM backs PHP. Un-named analyst makes a jab at Java

IBM backs PHP. Un-named analyst makes a jab at Java:
"IBM has announced that they are collaborating with Zend, of PHP fame. An un-named analyst got into the mix claiming that IBM is disillusioned with Java. What a bold comment. Give me a break."


Well... after building things like websphere I don't think big blu will drop java in favor of a scriting language such as php. But everybody knows that they throw a lot of money in experiments. PHP is Pretty Home Page so it isn't for the entrprise. I think I will register the domain www.php.biz and put this sentence on the home page.