Tuesday, July 21, 2009

Google App Engine - Spring Integration Issues

I'm currently building the server component of Beer Radar using Google App Engine and Spring Framework 3.0.

I've encountered these problems below and posting their corresponding solutions.

Problem:
Google App Engine cannot read JSTL and Spring Expression on JSPs

Solution:
Google App Engine has isELIgnored="true" by default.
Just add the isELIgnored="false" on the <%@page section in the JSP.


Problem:
org.springframework.web.servlet.tags.RequestContextAwareTag doStartTag: access denied (java.lang.RuntimePermission getClassLoader)

Solution:
Add the following on your Controller

For Annotated controllers use
@InitBinder
public void initLogin(WebDataBinder binder) {
System.out.println("initLogin");
binder.registerCustomEditor(String.class, new StringTrimmerEditor
(false));
}

For sub-classed controllers
Override the InitBinder method and register string trimmed editor in the binder
binder.registerCustomEditor(String.class, new StringTrimmerEditor
(false));


Problem:
org.springframework.web.HttpSessionRequiredException: Session attribute '' required - not found in session

and/or

Uncaught exception from servlet
java.lang.RuntimeException: java.io.NotSerializableException:

Solution :
implements Serializable {
private static final long serialVersionUID = <generated value>L

The unserialized Session object will work on development but, it will throw a java.io.NotSerializableException on the appspot server.


Problem :
Attempt was made to manually set the id component of a Key primary key. If you want to control the value of the primary key, set the name component instead.

Solution :
This happens when I update a child object. The solution for this, is to re-attach the parent object first, by
Parent attached = pm.getObjectById(Parent.class, detachedParent.getId());
then
Modify the child
attached.getChild().setName("new value");
then
pm.makePersistent(attachedDrunkard);

This solved the problem for me. Here's a link of a couple of alternative solutions.

Email

java.padawan@androidph.com