In this Grails Example, we add validation constraints to our model. This limits the data that an end-user can enter into our scaffolded views. Constraints in your model definition are automatically rendered in your scaffolded views. There are many types of constraints such as making a field required, unique, or one that only accepts a range of values.
Once we have our constraints in place, we will generate Static Scaffolding, which allows us to see the actual code behind the controllers and views that scaffolding uses. Using Static Scaffolding allows you to customize these files.
Video #15 shows how to enable data entry constraints and Static Scaffolding.
Hi Mike,
First of all thanks and 5 star for your efforts for all this videos and putting it together, it helped me quickly learn and leaverage the advantages of building quick web application, without much configurations. Thanks a ton..!!!
As stated by you i did used the same constraint min for the dueDate, but when i create the Project from UI, even if the date is same day it throws the following error which seems to me is related to the time stamp of the date instance
Property [dueDate] of class [projecttracker.Project] with value [4/1/13 12:00 AM] does not pass custom validation
It would be real great if you can help me fix the issue or anybody has any idea of what the issue is.
Thanks and Regards,
Ronak Thakrar
Good tutorial. I am wondering how can we validate the date format if user is entering date in a textfield instead of using drop down box. Let’s say date format required is ‘MM/dd/YY’ and user enters some other format so it should validate and gives some custom error message. Please guide. Thanks.
5 Star Work!
Great presentations! However, since I am using Grails 2.1.0. some of the displays are different, but was still working until this presentation. Even though I get a drop down for billableType and I selected one of the types in list, I am getting an error: Property [billingType] of class [class projecttracker.Project] cannot be null. Since this videos are for Grails novices as me, perhaps you should consider re-tape scuffling (dynamic, constrains and static) to reflect changes. Still, these videos are very helpful for quick understanding of the concepts.
Oh, forgot to say what was my solution. I added another constrain in billableType blank:true and it works. Now I can select any billable type.
I followed the video’s instructions until 7:53, when I tried to save the new Project, I got a validation error on UI claiming that “Property [owner] of class [class projecttracker.Project] cannot be null”… but actually I have already had a EndUser selected in the dropdown box. I tried to select different EndUsers from the dropdown but still no luck. There is no serverside error from the Eclipse console, and I checked in H2 Console that there are records available in the EndUser table. Anybody has a clue on this? Please kindly advice. Thanks in advance
Great job on these tutorials. They have been helping me a great deal getting my feet wet with Grails. I plan on doing a small app for a graduate class I am taking this summer.
Just thought I would add a tip of being able to generate those static files using GUI in STS. If you right click on a file in the package explorer go to –>New you can then select to generate controllers, views or controllers and views.
Glad they were helpful. Thanks for the tip. I like to stay in Eclipse as much as possible in the tutorials, so I’ll use that technique for future videos.
In the book Getting Started With Grails from InfoQ Scott Davis and Jason Rudolph address the min date constraint differently. According to them the min: new Date() value is set every time the server is restarted. The right constraint would be validator: {return (it > new Date())}
I haven’t tested this myself though.
Thanks for pointing that out. I verified that my constraint works as you said. It appears that constraints are only calculated once, at server start-up. Personally, I would consider this a bug, but it is only being treated as an inaccuracy in the documentation, which is what I was following when I created the video. I’ll try your solution and consider using it the next time I update the video.
Congratulations!!
Grails is very friendly, and with few hours of study I’m be able to develop my first application.
thnks
Thank you for your work here, the tuts are very helpful in seeing how grails is put together. Good job. Do you know why the “_” was automatically added to dueDate from the model to the H2 db? Thanks, Mark.