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>

Tuesday 29 September 2009

Publish failed using Ant publisher - duplicate entry

I got so frustrated this week with the eclipse + maven + glasfish combo.
It kept on refusing to publish my web project to glassfish with some lame excuse:
Publish failed using Ant publisher
unable to assemble module
duplicate entry: some.file

In any case I figured out a workaround (lucky guess):
Right-click on your project -> Maven -> Disable Workspace Resolution

Voi la. I can work again and debug my web apps.

Wednesday 26 August 2009

rocketfuel-setup could not retrieve key

I'd like to try out a in-house launchpad at some point,
so I thought I should get it.
But for some reason the rocketfuel-setup couldn't download
the keys it wanted for the dependencies it needed to apt-get:

Retrieving key 0A5174AF.
gpg: requesting key 0A5174AF from hkp server keyserver.ubuntu.com
gpgkeys: key 0A5174AF not found on keyserver
gpg: no valid OpenPGP data found.
gpg: Total number processed: 0
Could not retrieve key 0A5174AF.


So after mucking around trying to tell it to use my proxy,
I just commented out the relevant exit 1 lines.
This worked great, I just got prompted to confirm I want to install these packages.
I suppose the better solution would have been to try harder to manually install
the keys, but I didn't want to think about it too much.

Friday 14 August 2009

how to use apt-key so apt-get stops complaining

Use the last 8 digits apt-get gives you when it complains about keys eg.:

sudo apt-key adv --keyserver hkp://wwwkeys.eu.pgp.net:80/ --recv-keys 5ADC2037

(I'm just pasting it here so I can find it again)

Sunday 09 August 2009

xfce=a new lease of life for my not-so-old laptop.

Yes kde4 made my 64bit, 4GB mem, Core2 Duo 2.4GHz (kubuntu 9.04) laptop cry and die on me. For some reason it made X use a lot more memory than I would like.
So a couple of weeks ago I tried out xfce and I can be productive on it now. Although I miss a lot of features, at least I'm not running out of memory so easily and it does not crash so often anymore.
It may not strictly be Kde's fault, but by experimentation I found that xfce is better for me at the moment.