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:

You can reed this introductory article:

See some other cool examples to look at: (I was trying to implement this one just a couple of weeks ago)

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

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.reportColumnIndexSelectItemList}" />

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

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), 
An error occurred when processing your submitted information. ),
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:

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.reportColumnIndexSelectItemList}" />