Saturday 31 October 2009

Project Lombok: Put an End to Java Verbosity

If you're interested in java programming involving lots of beans, this is a crazy cool tool.

Its a combination of a compile-time and a development-time code generator, which has made Java POJO verbosity history.
It uses annotation magic to implement all the repetitive boring bean methods (getters, setters, equals, hashCode, toString)
without them actually cluttering your classes. Thats right it generates invisible code!

Now you have to watch the video at:
http://projectlombok.org/

You can reed this introductory article:
http://www.devx.com/Java/Article/42946/1954

See some other cool examples to look at:
http://projectlombok.org/features/Data.html
http://projectlombok.org/features/Cleanup.html (I was trying to implement this one just a couple of weeks ago)
http://projectlombok.org/features/EqualsAndHashCode.html

I came across lombok while trying to figure out if I can get eclipse to also generate the .equals and .hashCode methods
on new JPA entities like netbeans does. turns out it I don't really need that any more.

Saturday 17 October 2009

Saving a list of your Ubuntu packages and installing them again somewhere else

When you have to leave your old installation behind and have to move to a new installation of Ubuntu. You can install all the packages you used to have in 3 easy steps. Then you just need to copy over your home folder and voi-la your new installation is almost exactly like you used to have. On other operating systems this takes a week or so, and you keep on discovering things you forgot.

So for the packages you do on your old install:
dpkg --get-selections > installed-software

copy the installed-software file over to your new install and:
dpkg --set-selections < installed-software 
dselect
Like magic. And if you have a local apt-cacher-ng, you don't even need to download everything again. Alternatively you can copy over your /var/cache/apt/archives/ before doing the second part. http://www.arsgeek.com/2006/09/19/ubuntu-tricks-how-to-generate-a-list-of-installed-packages-and-use-it-to-reinstall-packages/ http://ubuntu-sos.blogspot.com/2008/06/how-to-create-and-restore-list-of-all.html

Tuesday 13 October 2009

(Ice)faces hates me and Richard

After Richard Kolb and I have struggled with this for days, I finally cracked it.

We defined some dropdowns, and radio buttons in icefaces eg:
<ice:selectOneRadio id="reportColumnIndexRadio"
value="#{scratchPad.reportColumnIndex}"
partialSubmit="true"
layout="pageDirection">
<f:selectItems
value="#{scratchPad.reportColumnIndexSelectItemList}" />
</ice:selectOneRadio>

<ice:selectOneMenu id="reportColumnIndex"
value="#{scratchPad.reportColumnIndex}"
partialSubmit="true">
<f:selectItems
value="#{scratchPad.reportColumnIndexSelectItemList}" />
</ice:selectOneMenu>

but when a new item was selected nothing happened, we just got this VERY cryptic log entry e.g:
sourceId=reportEditorForm:j_id14[severity=(ERROR 2), 
summary=(reportEditorForm:j_id14:
An error occurred when processing your submitted information. ),
detail=(reportEditorForm:j_id14:
An error occurred when processing your submitted information. )]

After hours of (debugging, guessing, googling, repeat) loops,
I finally found this link which explains it a number of times:
http://www.icefaces.org/JForum/posts/list/7965.page

Faces or icefaces does not automagically serialise or cache objects when sending it to the browser!
It converts to/from Strings if it can
and tries to waste as much of your time as possible if it can't!


So my fix was setting the selectItem's value to our DB Id in stead of the object,
using the Id property for the SelectOne value.
Then on partial submit when the setter gets called,
we have to iterate through the cached list to find the one matching the Id to set the real property.

<ice:selectOneMenu id="reportColumnIndex"
value="#{scratchPad.reportColumnIndexId}"
partialSubmit="true">
<f:selectItems
value="#{scratchPad.reportColumnIndexSelectItemList}" />
</ice:selectOneMenu>