I have just gotten started with Grails and I have a very basic application running. I want to pre-populate a hidden form field with a random string.
What is the best way to do this? I have looked at the taglib but I am not sure what the best practice is for this sort of thing. Should I create a class in the src/java or src/groovy folder or is there a better way to get this done?
Lastly, and I know this is a very basic question, but if I do create a class or taglib, how exactly is that called from within the .gsp page?
Thanks!
If your action looks like this
it means that a new
Orgobject is passed to your view which can be referenced asorgInstanceSince the model
[orgInstance: new Org(params)]is a map, you can simply add another parameter:This can be used in your .gsp in the following way:
Regarding your other question: a custom taglib is used in the same way as the other Grails-Tags:
<g:myTag ...>...</g:myTag> . You can change the namespacegto whatever you like -g` is the default. See the documentation for more details: http://grails.org/doc/latest/ref/Tag%20Libraries/Usage.html