You must be wondering how is Groovy on Grails and an expensive Ferrari are connected. The answer is that they are connected. To fully appreciate the neat features of Groovy on Grails, you have to sit with the language and get to know it over via your handy dandy IDE. Groovy on Grails may sound wonderful in the beginning however you realize that it is not that easy when you want to build custom functionality. I struggled with building form validation for fields which appear on web form but the data in these fields is not reflected in the database. Groovy on Grails may be a great language however it is like the dark ages in terms of documentation.
Anyway I figured all of my issues for this release and I also found a bug in the Groovy on Grails and a quick work around:
- I have a UserAccount class which looks like this:
class UserAccount implemments Serializable {
String username
String firstName
Address address = new Address()
static def constraints = {
}
} - I have a Address class which looks like this:
class Address implements Serializable {
static belongs =[user:UserAccount]
String streetAddress
String city
static def constraints = {
}
} - I have a gsp file
I noticed that the textboxes for streetAddress and city didn't highlight in red when the textboxes had invalid data. To get around this issue, I wrote a simple JavaScript function which manually highlighted the textbox if the error message for the textbox is generated. This how ever didn't work (this is the bug). Here is what I had for highlighting the city textbox:
${hasErrors(bean: person?.address, field: 'city', 'errors')}'
This didn't work on its own and the Javascript didn't work. After spending some time with this bug, here is how I resolved:
${hasErrors(bean: person, field: 'city', 'errors')}'
This made the JavaScript to work properly. Hope it helps