Thursday, December 16, 2010

Accessing spring beans from liferay templates

I had an interesting task, display the version of the portal.
The question which immediately arises is: how do I get from my velocity template to my spring beans?

1. The first stop is the VelocityVariable class from Liferay.
there your fine "serviceLocator" variable which sound just as the right variable to use.
2. In your tpl file add the following


  • $serviceLocator.findService("versionBean").getVersion()



3. You may think now that you only have to configure a Spring bean named "versionBean". Wrong!







The bean name must be augmented with ".velocity" and the bean you are talking to is not yours, but the "ProxyFactoryBean" in which you inject your bean!
4. The Java bean class is up to you then.

Thanks you Martin for your help with this one.

Wednesday, December 1, 2010

Choose default java version in Ubuntu

I got annoyed today, as I needed the sun jdk on my Ubuntu machine.
I had to goodle a while before finding how to change the default from open jdk to sun jdk

The how to is located here.

But I reproduce the text here:

Choosing the default Java to use

  • Open a Terminal window
  • Run sudo update-java-alternatives -l to see the current configuration and possibilities.
  • Run sudo update-java-alternatives -s XXXX to set the XXX java version as default. For Sun Java 6 this would be sudo update-java-alternatives -s java-6-sun
  • Run java -version to ensure that the correct version is being called.
You can also use the following command to interactively make the change;
  • Open a Terminal window
  • Run sudo update-alternatives --config java
  • Follow the onscreen prompt
I still would prefer some gui to perform this. But it is a start.