This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Entity field with --notNull --sizeMax

Dec 24th, 2009, 08:13 AM

Hi all,
I am adding a field "description" with the parameters "--notNull --sizeMax 4096" to an entity "License".
When running the generated web application, I manage to create a License without nothing filled in the "description" text area, while I would have expected to get an error message preventing me from creating the license since the field description is empty. Furthermore, I don't have a hint box telling the description cannot be empty.
For another field with "--notNull" that generates an html input, it does work: I've got the hint box telling the field is required and I can't create the license if I haven't filled the input.
Is there something I've done wrong or is my expectation wrong?

This is unfortunately a known issue which we cannot resolve easily. This is because what you are seeing is a Dojo shortcoming rather than a Roo problem. See https://jira.springsource.org/browse/ROO-440 for details. Effectively Dojo TextAreas do not have a 'required' attribute.

In order to trigger at least server side validation for your description field you should also define a '--sizeMin 1' attribute in the command which will check the length of incoming String values. The String itself is not null since the Spring MVC binding mechanism simply creates an empty String object.

Comment

Thanks Stefan!
I was wondering why there were no validation exception raised on the server side and thus, whether such field was initialized to null or an empty string.
I will use the workaround you've suggested.