Announcement Announcement Module
Collapse
No announcement yet.
Customizing controller to return other objects Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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?

      Comment


      • #4
        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.

        Comment

        Working...
        X