So as you may have seen in my last few posts. I spent most of the weekend creating my first grails plugin. My lovely wife is away for 3 weeks on holiday so I am blasting out all the little projects that I have wanted to do.
So I thought I would just write a little piece about my experience of writing the plugin. First thing i would like to say is what a pleasure it was to write and as how easy it was. So how did it come about.
Well I have been building my own application in grails for the last few months and one thing I really missed was client side javascript. I was quite suprised to find that there was no direct support for this in grails. In my day job we use the valang library that has greate support for generating client side javascript so I had gotten used to it. One thing I did find was this disbandond tag lib that sits in the grails core validate tag. So i looked at the source code for this tag and figured out what is was trying todo. It turns out that is was using the javascript support of the commons validation libarary.
So after some experimentation I realised I could resurect this and put it together as plugin to support client side javascript. So after some complicated things like getting access to the constraints object of command objects and generating i18n messages for the errors I finally put together the plugin in 4 releases over a weekend.
So things i found hard to do and never really managed to do it in a nice way was to mock out the grailsattributes object and grails application etc. My tag needs these to get access to domain and command objects but it is very complicated to mock them out.
Eating your own dog food.
So before i actually realeased the plugin i installed it in my own application and started using it in a real app. This turned out to be essential for testing. I found several issues that it did not handle. Things like: grails auto generating nullable constraints for all attributes of a domain class but not for command objects was tricky as you ended up with unecessary validation generated. So after a few rounds of tuning and robusting i realesed it.
Grails plugin release process.
It is so easy to release and re-release a grails plugin that you have to create one just to see that work. Auto tagging and versioning is handled so smoothly. But i guess i would not expect anything less from grails.
So to conclude if you have any greate ideas for a plugin then build them. There is nothing stopping you.
Remember someone once said that the saddest words of tongue or pen are these: "it might have been".
Ps. Version 0.4 is out now :)
Enjoy
15 comments:
Very cool and timely - I was just starting to look for this functionality today, and saw the news/announcement.
Thanks for creating this plugin.
Have you thought about support for in-line messages (e.g. error message next to each field, an error div/success div for each field) rather than just list/single div at top of page?
Yes all of the above should have it done this week. I also need it too :) Just takes some re-wiring of the apache commons validator code.
Thanks for your hard work Peter. This looks very cool indeed.
I just have a comment about your recommendation regarding the 'blank' constraint. I don't think 'nullable' is replacement for 'blank' simply because having blank fields in a form will automatically create empty Strings during the binding phase. So for most common form submissions 'nullable' doesn't even come into play. In those cases, 'blank' can be a simple and expressive constraint.
Why do you think it can mess things up?
Hi IKester
I think you are right. I posted about this on my blog take a look see what you think.
Thanks for working on this plugin idea. I have a very similar need. I'm glad to see your work out there! I'll take a look at it as I have time.
I'll also hopefully be eating my own dog-food again soon. I've learned that your "bowl" makes a big difference too. Some application servers serve up things differently and some databases will have subtle differences.
So try changing up relevant configuration bits to test things with. Not sure how that's applicable to you directly but for me it means switching between databases.
Good Luck!
I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.
Sarah
http://adoptpet.info
Hi Sarah
Thanks for your kind comment. I have been a busy at the moment with a full on project but expect some interesting posts comming up.
Pete
Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon.
This is really great. Keep it up the good going. Really very great blog this has given me all the information that i needed, good for visiting daily it will increase our knowledge. Best luck for future.
Do you have copy writer for so good articles? If so please give me contacts, because this really rocks.
Having read this material, I have learned for myself a lot of the new. Thanks
college board .
I suppose that Grails features dynamic methods on several classes through mixins. A mixin is a method which is added to a class dynamically as if the functionality was compiled in the program.
You are so smart! I'm impressed! How can you make it all!!
Why u thing that eating dog food it`s cool? It is terrible!
Good plugin, thank you for your great job.
Post a Comment