aspose file tools*
The moose likes Spring and the fly likes Edit object from a collection in JSP view Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Edit object from a collection in JSP view" Watch "Edit object from a collection in JSP view" New topic
Author

Edit object from a collection in JSP view

Dmitry Pidd
Greenhorn

Joined: Jan 13, 2011
Posts: 7
I'm writing Spring Hibernate website.




QUESTION!!
1. How to pass to JSP Father's Child's ID/NAME ?
2. How to address Father's specific Child's ID/NAME ?


Lets use analogy:




Flow goes:

-> Display listOfFathersChildren.jsp displaying list of Children Father has.

-> Clicking on one Child to edit

-> going to FatherController, passing fatherId, childId




Redirecting to "editChild.jsp"




Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1632
    
    7

What are you trying to do here?



children is a list of Child objects on Father so children[0] will be the first child in the list and children[1] will be the second and so on. So children[0].childId (assuming there is a childId field on the Child object) will be its id and children[0].childName will be its name.

[How To Ask Questions][Read before you PM me]
Dmitry Pidd
Greenhorn

Joined: Jan 13, 2011
Posts: 7
Thanks for reply Bill,
The question is how to reference Child I want to edit in edit child.jsp? If user clicked to edit 5th child in children list I cant cannot say




How do I specify child id/name dynamically? I could create new Father father in controller and add only one child to father's children collection since I know chid's and father's id's in controller

Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1632
    
    7

The way you are doing things now your Father object is your form backing bean. I was under the assumption that you were just going to bind the form fields to all the attributes on the father and his children (some of them will be hidden) then when the father is submitted back up to the controller you will call merge and update what is in the database. Is that correct? If it is then i would loop over the collection of children and show each one on the page allowing them to edit whatever they want (remember to bind every field to the form even if its a hidden field or else when it is submitted back up to the controller it will be null).

something like the below snippet:



Of course here we have only the childs name so this would not make the page to busy, but if there were lots of other editable fields you might want to do it differently. Maybe in that case you would want a page that lists a fathers children and when they select one you submit that childs id up to the controller and return a view that takes the child as the form backing bean and you edit just that one child's attributes and then update it. Once you get the basics down you might want to start playing around with ajax and data tables too.

edit: If you want to do dynamic things without submitting to the server you are going to have to look at javascript or one of the more prominent javascript libraries like JQuery.
Dmitry Pidd
Greenhorn

Joined: Jan 13, 2011
Posts: 7
You used magic word "backing bean"

Thanks!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Edit object from a collection in JSP view
 
Similar Threads
Spring problem (SimpleFormController)
Need Spring 3.0 help with annotations/setup
Hibernate mapping doubt
pagination exception in spring
Spring MVC + Hibernate: Update one column?