Monday, January 29, 2007

Making Your Spring Service Layer Classes Application Context Aware

Spring framework has a nice feature to make your service layer classes applciation context aware. Basically, wiht ApplicationContext you can get messages stored in properties file. For JSP pages this can be easily done with tag libraries. But from the service layer classes, it is quite difficult to get those MessageResourceBundel class and other configuration settings. By implementing ApplicationContextAware from your service layer class, you get a reference to the ApplicationContext object and read in whatever properties you want to read. Below is a code snippet:

public class xxxxController extends FormAction implements ApplicationContextAware{
..................


public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.appContext=applicationContext;
}
}

Once this code has be inserted, you are ready to get the messages in the properties file like this:

String message = appContext.getMessage("your desired message name", new Object[]{param1,param2}, Locale.getDefault());

where param1 and param2 are of any Object type that you want to inject to the message which has the format like this:

Hellow {0}, today is {1}......

Tuesday, January 16, 2007

Web 2.0 logo creator by Alex P (Alternate link)

Thanks to Alex for coming up with this kool piece of tool. It has attracted so many visitors that the main site is not working anymore. Here is the alternate link to generate the images http://h-master.net/web2.0/index.php.

Here's what I have created and the code I used to generate this image.
[c=FF0000]D[/c][c=00C400]O[/c][c=0000FF]R[/c][c=FF0000]I[/c][c=0000AA]S[/c]

Generated Image