Announcement Announcement Module
Collapse
No announcement yet.
Help with Using two models Please Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with Using two models Please

    Hey Guys, i am very new to Spring so please don't jump at me and get mad if my question is not to worthy .

    I have this big problem in my application that i been trying to solve for over 2 weeks.
    I AM USING spring 2.5 so please don't give me answers for 3.0
    First problem 1) Using two models
    Second Problem 2) Using check boxes
    Third Problem 3) Using MultiActionController (its a problem because i can't find many examples and most of the examples are SimpleFormController)
    Fourth Problem 4) Please don't send me to a link and tell me to read because i been reading crazy things over these two weeks and still can't find my sloution.

    so here is the example of which i am trying to do

    Code:
    one model will store all information of zzz
    public class ZZZ
    
    private long id;
    private String name;
    
    (getters and setters)
    
    
    
    and i have another model  YYY that has this 
    
    public class YYY
    
    private long id;
    Set<ZZZ> zzzs;
    
    (getters and setters)

    and then i have the DAOs as follows
    Code:
    public class YYYDAOImpl implements YYYDAO { 
            private HibernateTemplate hibernateTemplate; 
            
             public HibernateTemplate getHibernateTemplate() { 
                    return hibernateTemplate; 
                } 
              
             public void setHibernateTemplate(HibernateTemplate hibernateTemplate) { 
                    this.hibernateTemplate = hibernateTemplate; 
                } 
              
         
    
    
            public void saveYYY(YYY yyy) { 
                    // TODO Auto-generated method stub 
                    hibernateTemplate.saveOrUpdate(YYY); 
            } 
            
            @SuppressWarnings("unchecked") 
            public List<ZZZ> getZZZ() 
            { 
                    return hibernateTemplate.find("from ZZZ"); 
            } 
    }
    My Controller
    Code:
    public class YYYController extends  MultiActionController {
     private YYYDAO yyyDAO;
    (setters and getters)
    
            protected ModelAndView List(HttpServletRequest request,HttpServletResponse response) 
     { 
               List<ZZZ> zzzs = yyyDAO.getZZZ();     
               ModelMap modelMap = new ModelMap();
               modelMap.addAttribute("zzzs", zzzs);
              
    
                    return new ModelAndView("list.htm"); 
            } 
    
      protected ModelAndView save(HttpServletRequest request,HttpServletResponse response) 
     { 
               saveOrUpdate(YYY);         
    
                    return new ModelAndView("list.htm"); 
            }
    so here is what i am trying to do
    jsp
    Code:
    <body>
    
    i am using a displaytag table by the way 
    <form:form method="post" action="save" commandName="ZZZ">
    <display:table id="zzz" name="{ZZZ}">
    <display:column title="Select"> <input type="checkbox" name="selected"/>
    </display:column>
    <display:column property="name"/>
    </display:table>
    <input type="submit" value="Save"/>
    </form:form>  
    </body>
    so i am listing from one model and i want to save into a different model so
    1)how do you pass a list to the controller

    2)how to send selected value to the controller

    3) HOW to do this task?

    all my configurations are working great and i am suing spring 2.5 so please stick to the version when supplying help !
    Please help and know you are dealing with a newbie

  • #2
    Anyone guys? Please

    Comment


    • #3
      ModelMap modelMap = new ModelMap();
      modelMap.addAttribute("zzzs", zzzs);


      return new ModelAndView("list.htm");
      You are creating a new model instead of returning the one to which you have added your list. This way you are never going to get the list on your view! You should change this to(note that methods name first letter should be lowercase):

      Code:
      protected ModelAndView list(HttpServletRequest request, HttpServletResponse response) 
      { 
          return new ModelAndView("list.htm", "zzzs", yyyDAO.getZZZ()); 
      }
      Also, you are using the displaytag framework incorrectly. You use the wrong name in your display: table tag, it should match the name you used to save the model attribute, and it shouldn't be in brackets (displaytag doesn't use EL):

      Code:
      <display:table id="zzz" name="zzzs">
      with these 2 corrections, it should work.

      Comment


      • #4
        Thank you so much for your reply. i did the changes and things starting to look better now. I might have further issues and i hope you be able to help me. Thank you

        Comment


        • #5
          I suspect you're not getting much help here because your question isn't related to Spring Web Flow. Perhaps if you posted in the Web forum instead?

          Comment


          • #6
            Originally posted by InverseFalcon View Post
            I suspect you're not getting much help here because your question isn't related to Spring Web Flow. Perhaps if you posted in the Web forum instead?

            yes ...i actually solved the problem, Thank you so much and i will post in the right spot next time .

            Comment

            Working...
            X