I have a simple Groovy bean that looks something like this:
class GroovyBean {
Integer id
String title
}
This bean is then used on a JSP page to support a basic HTML form with a text input for the title. For the database, the title column is set to be non-nullable. This meant, when the user left this field blank and submitted, which is done via a POST, an exception was thrown. I found that the following change to the bean fixed this however:
class GroovyBean {
Integer id
String title = ""
}
I'm a bit perplexed how this fixed it however. What I question is what is happening now when the input for the title is left blank by the user and submitted? I'd think that this empty String I set by default would be overwritten by a null sent in from the HTML form, but that's not happening. Everything here appears to work correctly, including clearing out an existing title and resubmitting. If anyone could provide me information on how the generated setter from Groovy is handling this, it would be greatly appreciated. Thank you.