In this Grails Example, we will invoke a powerful feature of Grails called Dynamic Scaffolding. With a simple one-line command in our controllers, Grails will dynamically build an HTML 5 user interface that contains create, read, update, and delete (CRUD) functionality. The UI also recognizes the relationships between our models and adds the necessary links to connect parent and child data objects together, such as task to projects, projects to owners, etc.
Video #14 shows how to enable Dynamic Scaffolding on your models.
The solution for the null problem was to remove capital letter:
i.e. in ‘EndUser.groovy’ domain
class EndUser{
String Password
will cause Property [password] of class [class projecttracker.EndUser] cannot be null
instead use camel case! i.e. password
class EndUser{
String password
this will work, scaffolding appears to require camel case
Using empty constraints for ordering fields is currently broken in Grails. They have the fix scheduled for Grails 2.2.2.
Great videos! I got to this site from grails.org. The videos are easy to follow and very well done.
A comment for Grails 2.2.0:
The redirect wasn’t working for me in the index method of the controller. According to this page on grails.org: http://grails.org/doc/latest/ref/Controllers/redirect.html, the action parameter in redirect requires quotes in Grails 2.2.0. Thus, I updated to the following and it works:
def index = {
redirect (action: “list”)
}
In case anybody else encounters this problem!
Great video; but like others, I am getting the Property [fullName] of class [class projecttracker.EndUser] cannot be null exception (and two more for the other fields), and have not seen any response to that…
Just a follow up on this… after adding the constraints and toString, I no longer see this problem…
i have this error in dynamic scaffolding
Property [fullName] of class [class tracker.EndUser] cannot be null
Property [password] of class [class tracker.EndUser] cannot be null
Property [userName] of class [class tracker.EndUser] cannot be null
i put all the date but when i click create i get this error.
Nice series. Only complaint: the tutorials were numbered up to 13. I figured out that this was 14. It would be nice numbering throughout.
Thanks
Thanks for that feedback. I got a bit sloppy in that regard when I added the Course Outline page. I went back and numbered the remaining three videos.
Thanks for this interesting tutorial.
I noticed that when you created a project the Owner was populated by an EndUser. How is that possible because when you created the EndUser you did not add a project to it.
I’m kinda new to groovy and to Grails, however I am a seasoned Java developer with reasonable knowledge in Spring.
The tutorials are great and I am able to make steady progress watching them whenever I can spare time.
Everything made sense to me so far and I was even able to anticipate the part when you changed the index method to point to the implicit ‘list’ method.
But I am confused over one thing, In the ‘toString’ method you used ‘${name}, why not just return the ‘name’ variable?
I am used to see this kind of makeup inside script pages such as GSP and JSP.
Why use it inside a groovy class? are there any disadvantages for returning the ‘name’ variable?
Many Thanks,
Yaniv
I still get the “The “endUser cannot be null” exception. I already tried the following:
1) Change to “create-drop” in the DataSource settings
2) Changed it back to memory in the DataSource settings
3) Deleted the EndUser.groovy file and created it new
4) Deleted the *.db files
I’m able to add a new project via the dbconsole but not via the Grails app. What else can I do?
It seems that this was a problem of Grails 2.1.0. I upgraded to 2.1.1 and the problem vanished.
I think I solved it: change the Datasource.groovy settings from “update” to “create-drop”. At least I can continue with the tutorial
as there might be a better explaination or solution to all this.
Yes, that is the best solution. I think I mention this in one of the later tutorials, but if you have it set to “update” Grails will try to leave your database tables intact and just apply the changes you make to the columns. However, some changes cannot be made through an update such as changing the type from character to number or in this case adding a column that requires a value when there are already rows in the table. Setting it to “create-drop” deletes all the tables and data when you start the server so that it can create the tables from scratch without any conflicts. It is the best setting for your development area since the tables change a lot when you are building your application. There are ways to “bootstrap” test data into the tables so every time it drops them, it re-adds your test data back into the table.
Hi
Despite the fact, that I’ve changed Datasource.groovy settings to “create-drop”, I still get the same error as Jay, everytime while compiling.
I also have problems on the runtime. The “endUser cannot be null” exception appears when I create a project due to your instructions.
Please help me if you can
Hmm.. I tried to delete devDB files after stopping server and changing dbCreate to ‘create-drop’. But after ‘run-app’ I still got the also the same errors:
Property [fullName] of class [class grails_test1.EndUser] cannot be null
Property [password] of class [class grails_test1.EndUser] cannot be null
Property [userName] of class [class grails_test1.EndUser] cannot be null
At least helps if I created EndUser.groovy again and started web-application again.
Great tutorials. I have facing this error problem while trying the dynamic scaffolding.
| Loading Grails 2.0.3
| Configuring classpath.
| Environment set to development…..
| Packaging Grails application…..
| Running Grails application
| Error 2012-05-11 13:51:54,427 [pool-5-thread-1] ERROR hbm2ddl.SchemaUpdate – Unsuccessful: alter table project add column owner_id bigint not null
| Error 2012-05-11 13:51:54,429 [pool-5-thread-1] ERROR hbm2ddl.SchemaUpdate – NULL not allowed for column “OWNER_ID”; SQL statement:
alter table project add column owner_id bigint not null [23502-164]
| Error 2012-05-11 13:51:54,432 [pool-5-thread-1] ERROR hbm2ddl.SchemaUpdate – Unsuccessful: alter table project add constraint FKED904B195D45685E foreign key (owner_id) references end_user
| Error 2012-05-11 13:51:54,433 [pool-5-thread-1] ERROR hbm2ddl.SchemaUpdate – Column “OWNER_ID” not found; SQL statement:
alter table project add constraint FKED904B195D45685E foreign key (owner_id) references end_user [42122-164]
| Server running. Browse to http://localhost:9000/ProjectTracker
Any ideas? Could it be the difference the grails version?
if comment out this line “static belongsTo = [owner:EndUser]” in domain “Project” I don’t get the errors.
Weird. The problem seems to manifest only with the drop-down component… Well, my new job consists grails development, so maybe I can give you the reason later
Hi. I’m reviewing your Just Spring book and wntaed to download the examples from o’reilly. Do you have a zipped version of the example directory? At present, they’re only offered to be downloaded a file at a time, which is rather painful and time-consuming. Thanks, Ken
Thanks for these tutorials. I booted the grails project and got a “endUser cannot be null” exception when creating a project while following these instructions. Rebooting grails-app seemed to fix the problem. Something to do with dynamic scaffolding? I don’t know how grails works, but it should do some runtime compiling (hence dynamic, right?). I actually am able to reproduce this problem with every new change I make and always it goes away after second “run-app”.
Hi!
Firstly thumbs up for these excellent tutorials!
Secondly I would like to point a small inconsistency between this and previous tutorial – Designing the Data Model. At the end of the previous tutorial you didn’t have any constraints defined in domain classes, but at the beginning of this tutorial there are some method calls in there. Not a big deal, but it would be nice to know how and why those constraints got there and what exactly do they do
Good catch. I’m not sure why those are there at the beginning of the video. I run through the exercises several times to ensure they will work smoothly for the video. Perhaps I didn’t revert before recording the screencast. As you found out by watching the video, those constraints order the fields for the dynamic scaffolding views. I’ll make a note of it and clean it up in the next revision of the videos. Thanks for watching and I’m glad they were helpful.
Mike,
When is the example for static scaffolding coming up? Waiting for it eagerly. Excellent job by the way
super example,
Step By Step ,
excellent work.
Its a pitty, that it takes some more weeks till end.