Announcement Announcement Module
Collapse
No announcement yet.
Writing My Own Controllers Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Writing My Own Controllers

    I am uncertain about beginning working with my own Roo-generated controllers. I create a custom controller:

    controller scaffold --class ~web.SizeChartController --entity ~admin.Measurement

    and I am unsure what I am looking at or how to proceed. After researching this I see that @Controller and @RooWebScaffold annotations establish this class as a controller, but of what type?

    For example, what if I want to make this a SimpleFormController- can I still do that? Do I define it in the annotations or with an extends statement?

    Also: let's say I want this controller to return an entity for editing... what is the proper process for doing that? Say the entity has a generated id, do I need to create a finder for that entity and use that code in my controller to fetch the object?

    Thanks.

  • #2
    If I make this too general, please ignore. Hopefully this will be useful to you.

    General rules with dealing with Roo source code and webapps (some of this is found in the Roo documentation).

    - don't touch the .aj files - they are system generated - read them to understand what they do, but never change them by hand. In fact, you don't need to even check them in. Just run roo shell when you update your source code.

    - in general, any java class that is created can be modified by you later. They won't remove your implementation code. Everything generated is either generated once (like the Data-on-demand Java files for testing) and can be edited, or overwritten at will (like any of the *_Roo_Feature.aj type aspectJ files) and should be treated as untouchable.

    - the views implement their logic using a set of custom tag libraries (found in WEB-INF/tags/form (and /form/field). These TAGX custom tags wrap the features of Spring MVC form tags, Tiles layouts, and Spring Javascript / Dojo widgets.

    - in the view pages, you can customize a form tag like <form:input> - make sure whatever you do, change the z="somelonghexnumber" to z="user-managed" so Roo doesn't replace your code later. Spring Roo uses the 'z' parameter to track whether it or you is managing that field representation.

    - if you want to change the implementation of something in the aspect files, either copy/paste it into your class and fix it (roo shell will fix it up once it sees you've saved the Java source file), or try to get Springsource Tool Suite to refactor it by using the Push-in feature. I've done that for several things I wanted to change.

    If you're looking for what type of controller Spring Roo implements, I wonder if you may be more familiar with Spring MVC or 2.0's XML-and-base-class implementations. Spring MVC 3.0 (and 2.5) implement an annotation-driven POJO controller mechanism.

    I recommend you take a look at the Controllername_Roo_Controller.aj file and the scaffolded views to get an idea of what is possible. Beyond the slightly different Aspect J ITD syntax, which generally pre-pends the class name to everything, it's straight Java. At compile time, every method in the .aj files gets added to the bytecode of the Java class.

    If you want to build your own controllers, you can use controller class instead of controller scaffold - and then build the controller straight from scratch. Also you should read up a bit on Apache Tiles since every time you add a new view, you'll have to edit the views.xml file in the same directory as the view to add the new view name. I cover all of this in Roo in Action - which is in MEAP - in chapter 5. Not that I'm trying to get you to buy the book, but it's out there.

    Also, I recommend you download the Spring samples project from SVN - it's moving to Spring's git site I think soon, but for now you can get it with

    Code:
    svn co https://src.springframework.org/svn/spring-samples
    In there you will find the Spring MVC showcase, which has a lot of examples of various types of Spring controllers.

    Comment


    • #3
      Hi krimple,

      I'v failed to check out the specified svn via STS/Subclipse plugin as import->svn-> new repository.

      Error message:

      Code:
      An internal error occurred during: "Fetching children of https://src.springframework.org/svn/spring-samples".
      org/tigris/subversion/javahl/Revision$DateSpec
      Any hints on this? Has the repository been moved?

      Regards,
      Daniel

      Comment


      • #4
        Originally posted by DanielA View Post
        Hi krimple,

        I'v failed to check out the specified svn via STS/Subclipse plugin as import->svn-> new repository.

        Error message:

        Code:
        An internal error occurred during: "Fetching children of https://src.springframework.org/svn/spring-samples".
        org/tigris/subversion/javahl/Revision$DateSpec
        Any hints on this? Has the repository been moved?

        Regards,
        Daniel
        I think this may be an error on your SVN client. What version are you using? Tigris is a vendor for Subversion - I think JavaHL is some sort of provider / plugin to access the SVN resources. Are you doing this from Eclipse/STS? If so, just go get the command line SVN client and use that.

        FWIW I just did a checkout using SVN 1.6.13 on Mac OS X Snow Leopard and got the entire tree...

        Ken

        Comment

        Working...
        X