Results 1 to 4 of 4

Thread: Controller generated code redundancy

  1. #1
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default Controller generated code redundancy

    So in class today, I was showing the students some of the .aj controller code while doing the Web MVC and RESTful Web Services sections and someone asked about how validation/exceptions are automatically handled and the form page automatically showing the fields in error.

    So while looking at the code there was some redundancy in methods.

    if (bindingResult.hasErrors()) {
    model.setAttribute("xxx", xxx.getAllxxx());
    more of the same
    }

    And that code would be in 4 or 5 methods.

    First, wouldn't that repetitive code cause many extra calls to the database that aren't needed.

    And secondly, can that code be refactored into just a private method that all the other methods call?

    Thanks

    Mark

  2. #2
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    668

    Thumbs up

    Quote Originally Posted by bytor99999 View Post
    First, wouldn't that repetitive code cause many extra calls to the database that aren't needed.
    I don't think so, because at most one of those methods is called per request, and each of those methods (createForm, create, updateForm, and update) needs to put the reference data into the model in order to (re)display the form.

    Quote Originally Posted by bytor99999 View Post
    And secondly, can that code be refactored into just a private method that all the other methods call?
    Yes, and that's one of the first things I do whenever I need to push those methods into my controller's Java class for any reason (e.g. to filter or sort the reference data in some special way). Having that code in a resuable private method in the AspectJ file would definitely cut down the work involved in pushing those methods in. How about you log it as an improvement?
    Andrew Swan
    "Now is the EJB of our discontent made glorious Spring"

  3. #3
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    Andrew, please log it as an improvement if it would help you. You're using Roo a lot so if you're finding a regular need to push-in and it would be easy to address we would be quite keen to hear about it.
    Ben Alex
    Project Founder, Spring UAA, Spring Roo and Spring Security

  4. #4
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    668

    Thumbs up Done

    Logged as ROO-663.
    Andrew Swan
    "Now is the EJB of our discontent made glorious Spring"

Posting Permissions

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