PDA

View Full Version : Customizing scaffolding templates



marceloverdijk
May 24th, 2009, 06:24 AM
Is it possible to customize the scaffolding templates or should I file a JIRA?

Currently create, list, show and update jsp's are generated together with the controller code.
I like to:
1) per project change the jsp templates mentioned above
2) per project change logic in the controller
3) per project add jsp templates or remove templates (e.g. adding a search.gsp)
4) per project add controller actions (e.g. for searching)

Stefan Schmidt
May 24th, 2009, 07:34 PM
Hi Marcel,

Thanks for your interest in the current MVC scaffolding addons.

Let me answer your questions below:


1) per project change the jsp templates mentioned above

1. We have gone to great lengths to separate out the JSP view add-on from the add-on that generates the MVC controller artifacts. The JSP add-on ships with a number of template files (CSS, images, header.jsp, footer.jsp, etc). This should allow you to change these artifacts as desired and therefore adjust them for your needs. We also currently generate most of the jsp files for the list, create, update and show functionalities. There is a class in the JSP add-on which takes care of most of this work (JspDocumentHelper). So if you want the change the JSP XML code generated for the individual views you would need to change this class.

2. You can generate all view artifacts first and then switch off automatic view artifact handling by Roo by specifying @RooWebScaffold(automaticallyMaintainView = false). Roo will leave your artifacts alone from then on and you can go ahead and customize them to your liking.

This is certainly something we will need to review for future releases so that it becomes easier to customize view artifacts. We are aware of this and there is a Jira ticket for it: http://jira.springframework.org/browse/ROO-8


2) per project change logic in the controller

The easiest way to approach this would be to generate controller artifacts as before and then just pull the methods you want to customize from the AspectJ file (.aj) to the controller (.java). All you need to do is to remove the class name from the method name. The add-on will recognize the method by name and not generate it in the aj file again. This way you have full manual control over this method from there on without any interference of Roo.

You can actually create controllers manually ('new controller manual') and implement any methods you like. This gives you full control over the activities of the controller.


3) per project add jsp templates or remove templates (e.g. adding a search.gsp)

Removing templates should be possible by specifying individual methods that should not be implemented i.e. @RooWebScaffold(create = false, delete = false) this is possible for create, delete, list, show and update. Again, this is something that may need some extra work on our side. Please open Jira tickets to make suggestions or notify us of problems.

Adding artifacts is currently not supported out of the box and does require a little coding on your side. Take a look at JspDocumentHelper and JspMetdataListener as a staring point.


4) per project add controller actions (e.g. for searching)

This is something I am planning to work on soon. At the moment we have an addon which generates custom finder methods for your domain objects. To see this in action try the 'list finders for' and 'install finder' commands. This will generate methods on your domain objects which can then be exposed to the controller and view. I am planning to integrate the finder add-on with the controllers and view artifacts soon (http://jira.springframework.org/browse/ROO-43).


So, as you can see there is still a lot of things we can do and your feedback goes a long way. Please feel free to open new Jira tickets to make suggestions or notify us of problems.


Best,

Stefan Schmidt
SpringSource

marceloverdijk
May 29th, 2009, 12:16 AM
Hi Stefan,

I think I had written a confusing question.

I'm just wondering if there will a Grails-like install-templates feature in Roo.
I don't know if your familiar with Grails but this command will install the templates to your project instead of using the ones in the core distribution. This way you can change the code generated by scaffolding as the templates are used to generate controller and gsp's.

Grails by default has a controller template and various .gsp (create, edit, list, show) templates. If I add a search action in the controller template and add a search.gsp the scaffolding generator will pick these up automatically.

What do you think?

Stefan Schmidt
May 29th, 2009, 06:07 PM
Hi Marcel,

Thanks for making these suggestions. As mentioned in my last message, we are aware that the current version of Roo does not support view artifact customization to the extend we would like it too. Hence the ROO-8 Jira ticket.

In my last response to your question I just tried to outline what is possible using the current release of Roo.

You did the right thing to link this forum thread to the Jira ticket so we can keep track of ideas. Keep in mind Roo web scaffolding is still in it's early stages and we are currently collecting feedback to see what makes sense to the community.

Cheers,
Stefan

elliottc
Feb 5th, 2010, 10:30 AM
The easiest way to approach this would be to generate controller artifacts as before and then just pull the methods you want to customize from the AspectJ file (.aj) to the controller (.java). All you need to do is to remove the class name from the method name. The add-on will recognize the method by name and not generate it in the aj file again. This way you have full manual control over this method from there on without any interference of Roo.

You can actually create controllers manually ('new controller manual') and implement any methods you like. This gives you full control over the activities of the controller.



When I try moving a controller method from the .aj to the .java for customization, the remaining methods in the .aj stop functioning.

For example:
Moving Foo.list(...) out of FooController_Roo_Controller.aj and into FooController.java as list(...), and then re-building. The result is that list(...) works fine, but Foo.show(...) and the rest of the .aj methods throw exceptions such as


No matching handler method found for servlet request: path '/foo/1', method 'GET', parameters map['y' -> array<String>['3'], 'x' -> array<String>['5']]

It appears that disturbing my web scaffold controller causes it to stop working?

edca
Oct 19th, 2010, 09:59 AM
Hi,

I am trying to generate custom view aswell and for that i created a package for my new controllers in: project.home.domain.controllers

As these controllers may have different functionality i decided to copy (not move because aj files must not be touched beacuse they are maintained by roo) the methods that i need from the aj file into my controller java file. Method names starting with the class name must be removed, and the return values of the methods should also match the names of your own views (tiles and jspx).

By now it works (not totally as i still have some fine tuning to do) but you can try it.

Hope this helps :)