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

Disabling Windows 7 Live Preview Feature when using Alt+Tab

July 26, 2012

Bored or confused with windows 7 live preview when pressing Alt+Tab and going through the screens to find the window you need? You can disable it in the registry:

Simply create a key called HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\AltTab and add a DWORD called LivePreview_ms with a value of ffffffff.

Thanks to Codehunter (found here (german)

Determining own directory path in unix bash script

August 12, 2011

In a unix bash script, you can determine the scripts filesystem location by using

SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"

This is especially useful if you want to use “relative” (well, sort of) paths within your script, regardless of which directory the script is being executed from, e.g.

java -jar $SCRIPT_DIR/libs/some-file.jar

If you just used libs/some-file.jar the bash script would only work when executed from the directory it is located in.

Cancellable startup script for Windows

August 12, 2011

Tired of starting all the programs you need after booting your computer day by day? Yay, just create shortcuts to all of them in the Startup directory, Windows will take care of starting them.

So well, works fine… as long as everything else is fine. For most people in IT, it is just a matter of time until there is a more or less urgent emergency to be fixed ASAP (e.g. fixing a web application that has crashed). Here you go: Argh, just wanted to connect to the server and fix the problem, but the computer is more or less unresponsive due to 20 programs starting at the same time. Sorry users, you will have to wait some minutes until my computer decides to be cooperative again. It would be great if one could avoid auto starting if needed.

Batch script to the rescue: The following script waits about 10 seconds before it begins to start the programs, giving you an option to cancel it.

Put the following batch script anywhere on your computer, create a new folder personal-autostart next to it, and put shortcuts to any programs you want to automatically startup with Windows into this folder. Then just add a shortcut to the batch script to the windows startup directory.

@Echo off
echo Personal startup script - hit Strg+C to cancel
echo ##############################################
echo Will start in about 10 seconds:
for %%i in ("personal-autostart\*") do echo %%i
echo ##############################################
echo Personal startup script - hit Strg+C to cancel

@ping -n 10 -w 1000 > nul
for %%i in ("personal-autostart\*") do "%%i"

Blocking Google and Facebook Requests on other Websites

February 22, 2011

Nearly every webpage is requesting additional files from Google or Facebook servers in these days, e.g. when making use of the very much discussed Google Analytics or Facebook Like Button. Of course, there are more: Google Web Fonts, Google Charts, Google Adsense, Google Apis, Facebook Connect, Facebook Widgets, etc., etc. The list keeps growing.

Why is it bad to have third party requests in web pages?

Of course, it slows down your web experience. But what is even worse, especially when it comes to Google and Facebook: for every request to their servers a cookie (and of course, your IP) is sent along allowing them to recognize you and compile a (nearly) complete profile of your web activities. This is especially bad when you using one of their services with login, because they can attach your activity to your confirmed identity without any doubt. But be aware that they are probably tracking all of your activity even when you are logged out.

What can you do to avoid Google and Facebook violating your privacy?

Block their content. As their Third-Party-Code is embedded in nearly every website (often, you do not even see a Google or Facebook feature on the surface) you cannot simply decide not to use their features.
The Ghostery Addon for Mozilla Firefox seems to be a good way to accomplish this.

Getting the maximum volume out of your Sansa Clip plus

February 4, 2011

The maximum value of the Sansa clip plus is fair, but sometimes a little more would be good, escpecially when listening to audiobooks.

Here you go:
* Settings > System Settings > Reset Factory Settings
* Choose your language
* Choose “Rest of the World” as region
* You will then have an additional option in the settings menu to increase the volume \m/


OALL8 is in an inconsistent state

February 24, 2010

Just had an exception due to this error when executing a database query to oracle using hibernate, all of a sudden – this has never happened before.
“The internet” implies this problem is probably caused by different Oracle versions, driver incompatibilities or likewise. As I have not changed anything about my database recently, this was not the case for me.

By debugging the code line by line and evaluating different expressions while doing so, I found out that the real problem was the odd heap space error, when retrieving a large result list from a hibernate query.

Increased memory for my app using -Xmx1024M, this did the trick. Not sure why no meaningful exception message was issued.

Incremental search for JavaDoc in FireFox

November 23, 2009

The following Greasemonkey userscript will add an incremental search feature to any JavaDoc displayed in the browser.

In order to use the script you’ll need the Greasemonkey addon, too:

Facebook Apps: “Session key invalid or no longer valid”

November 16, 2009

My facebook app worked fine for months, however all of a sudden it broke for some (not all) users. Sometimes, not always.
buru on brails has pointed me to the right direction when trying to solve this issue: obviously the session key parameter returned by the Facebook API (fb_sig_session_key) is not the actual session key for offline access as one would expect. (At least not always… huh)

Retrieving the session key from the cookie “YOUR_APP_KEY” + “_session_key” solved my problems.

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 🙂