Results 1 to 2 of 2

Thread: Regarding good OO design and spring ModelView

  1. #1
    Join Date
    Jun 2011
    Posts
    117

    Default Regarding good OO design and spring ModelView

    Hi Guys,

    I am using spring mvc and recently i had conversation with my colleague.

    Some of my Jsp's uses conbo box. Values for this combo box are populate using form tag of spring.
    ModelAttribute stores object that is used by spring to render other values of form.

    So I populate the list which is used to render combo box in a object which is used as modelAttribute and place that object in ModelAttribute and return it.

    I was told by my colleague that its poor OO Design since this list is required only for display i should populate it separtely in ModelMap rather thann the POJO
    eg:
    say i need to show state.jsp then in my stateController i have
    Code:
    public String getState(ModelMap map){
    map.addAttribute("State",entityObject);
    }
    In above eg this entityObject is the object which contains list of states and some data which is used for rendering the jsp
    my colleague says it should be

    Code:
    public String getState(ModelMap map){
    map.addAttribute("State",entityObject);
    map.addAttribute("stateList",listOfStates);
    }
    Please let me know what is right design so that i can take corresponding decision


    Thanks and Regards
    Patil Abhijeet
    In Rat race who ever wins or looses still remains the Rat.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default


    I was told by my colleague that its poor OO Design since this list is required only for display i should populate it separtely in ModelMap rather thann the POJO
    Which is correct. The POJO should only be for holding the form data not the referenced data needed to render lists etc.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

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