Archive for July, 2008

A simple java.util.Date to java.sql.Date converter

Thursday, July 31st, 2008

If you're using JSF and need a converter for converting UI elements (typically java.util.Date) to your domain object's date field (typically java.sql.Date), here's the code snippet, [java] public class DateConverter implements Converter, Serializable { public Object getAsObject(FacesContext context, UIComponent component, String value) { java.sql.Date sqlDate = null; ...

Gmail Tip

Monday, July 28th, 2008

I read this today; I didn't know you could manipulate gmail addresses in such a way.

Spring Integration Presentation with Mark Fisher

Monday, July 21st, 2008

I had a chance to attend Mark Fisher's presentations a couple of times before at NEJUG. This time around, it was a local Java Meetup group in Cambridge. He's a very humble and knowledgeable guy about a lot of things, from Spring to Hibernate to Seam, to Scala & MDA! With ...

Example Interceptor in Seam, EJB3

Sunday, July 20th, 2008

It's insanely easy to write an interceptor in EJB3. Here's a tutorial/example code for an interceptor which collects statistics info around a method invocation. [java]import java.util.Collection; import javax.interceptor.AroundInvoke; import javax.interceptor.InvocationContext; import org.apache.commons.lang.time.StopWatch; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class StatisticsInterceptor { private static final Log log = LogFactory .getLog(StatisticsInterceptor.class); @AroundInvoke @SuppressWarnings("unchecked") public Object intercept(InvocationContext ctx) throws Exception { StopWatch stopWatch = new StopWatch(); stopWatch.start(); Object result ...

Groovy Environment Scripting

Thursday, July 17th, 2008

Problem: You want to use groovy all the time, but ignorant (but paying) forces keep you writing verbose tedious Java code instead. Solution: Use groovy instead of shell scripts! In large Java development projects, developing in a local environment comes with a maddening list of pulling levers, pushing buttons, and spinning ...

Memory Leaks in Java

Wednesday, July 16th, 2008

[java]public class MyClass { private ArrayList list = new ArrayList(); public void addFoo( Object foo ) { list.add( foo ); } public void processFoo( Object foo ) { // Get foo out of the list Object fooRef = list.get( foo ); // Do something with fooRef ... // Done with fooRef, destroy it fooRef = null; } }[/java] In this example, the addFoo() ...