Sunday, March 8, 2009

Grails GSP concatenation nuance

While working with GSP it is a common situation to perform actions with strings, domain objects or other classes. Recently I faced the simple situation where I needed to dynamically build full file name (with file extension) in order to allow user to download it from file system. In my simple GSP I created the code similar to listed below:



I use concatenation of strings in order to build full file name. But at runtime exception occurred which was very strange and gave me no tip for possible mistake made. As I discovered later in my example You can not use dot in double quotes (".") cause Grails wants to interprete expression in them and fails.
Therefore You can solve mentioned situation in two ways:
  • Use dot in single quotes ('.'). In that case correct solution might be:


  • Move mentioned logic to some separate class (for instance, let's call it DocumentFileNameBuilder) and call it as it listed below:


Simple stupid issue solved :)

4 comments:

  1. Or just roll your own taglibrary, that would be nicer.

    ReplyDelete
  2. Thank you for the advice, my simple stupid issue is now solved ;-)

    ReplyDelete
  3. It's pretty helpful,i should recommended it to my freinds.
    thanks
    document finder

    ReplyDelete