Results 1 to 4 of 4

Thread: Customizing controller to return other objects

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    3

    Default Customizing controller to return other objects

    Sorry if this is very basic, but I'm very new to Roo. I have a controller that was created by Roo. I want to customize to return extra objects. I see this method in AccountController_Roo_Controller:


    Code:
     @RequestMapping(value = "/{id}", produces = "text/html")
        public String AccountController.show(@PathVariable("id") Long id, Model uiModel) {
            addDateTimeFormatPatterns(uiModel);
            uiModel.addAttribute("account", Account.findAccount(id));
            uiModel.addAttribute("itemId", id);
            return "accounts/show";
        }
    I would like to add a couple extra objects to the Model at this level. Where should I do this? Should I edit this method here?


    Thanks,

    Andres

  2. #2
    Join Date
    Jun 2012
    Location
    Bangalore
    Posts
    4

    Default

    when ever you create controllers by using roo, it will generate .aj(apectj) files (AccountController_Roo_Controller.aj in your case) with few methods to serve basic requests operations. All these files are managed by roo every time. will be deleted updated all the time by roo.

    One way you can push the generated code by using Refractoring.(alt+ctrl+T-> PushIn)
    Later you can add your code now.
    in another way you can only copy one method from aj file to your controller and delete the method from aj file. now you can add your code in the method.
    Finally possibility :
    You can write your own method in the controller and map your request to that method


    Thanks
    Nare

  3. #3
    Join Date
    Feb 2013
    Posts
    3

    Default

    Quote Originally Posted by ciggic View Post
    in another way you can only copy one method from aj file to your controller and delete the method from aj file. now you can add your code in the method.
    Thanks for your answer. This looks the closes to what I want to accomplish. So if I copy the method from AccountController_Roo_Controller to AccountController.java, I can make the changes there? Should I make any changes to the aj file so the method doesn't get regenerated?

  4. #4
    Join Date
    Jun 2012
    Location
    Bangalore
    Posts
    4

    Default

    Yes.. you can delete the method from aj file and add in the AccountController.java with the same prototype. Now roo will not regenerate the same method in aj file . Now you can customize according to your requirement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •