Posts Tagged ‘web development’

How to customize error messages for command objects in Grails

August 24, 2012

Basically, it works as it does for domain classes (see Grails documentation on validation).

However, command objects are often subclasses of controllers. Keep in mind that with subclasses it is *not* just like myCommandObject.myProperty.blank.
Instead, you have to write myParentClass$MyCommandObject.myProperty.blank. That’s it.

By the way: if you encounter problems with custom error messages not displayed, this is very easy to debug. Just create a breakpoint and inspect the command object, have a look at errors.errors[i].codes, it contains all message codes Grails will try for this specific error with index i

Force page reload on back/forward button in Firefox 3.x

November 16, 2009

When using the back/forward buttons in FF3.x, pages are cached and delivered from cache very strictly. Obviously (unlike normal caching) even page headers like Pragma, Expires etc. are ignored. This special cache is often referred to as bfcache (back/forward cache).

This behavior caused exceptions in my wicket app, where ajax funtionality is used, here’s what happens:
* Load page containing panelA
* User interaction, replacing panelA with panelB using ajax
* User clicks back button
* User clicks forward button
-> initial page content (markup) is loaded from fbcache, including panelA
-> in wicket pageMap, panelA is not existent, since it has been replaced with panelB
* User interacts with an ajax element on panelA
-> exception is thrown “Component x not found on page”

Solution: add an unload handler to the page’s body tag. This causes firefox to reload the page instead of simply grabbing it from bfcache, so that server and client side state is in sync again 🙂