• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Edit object from a collection in JSP view

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"




 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Dmitry Pidd
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You used magic word "backing bean"

Thanks!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic