• 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

Using Spring Form tag for Edit Functionality

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

In my web app. I have a domain Object(bean) which i have mapped to one of my tables via hibernate, i have used the same domain object reference to a spring form tag in my "addcustomer.jsp" which is used to add customers, this way whenever a customer is added spring form tag fill's up my domain object and i can persist this to my DB. However, when i use the same technique in my "editcustomer.jsp", the domain object that i get in my controller flushes all the fields information and only gives me that information which has been changed/edited. Hence, i cannot blindly persist this entire domain object to my db as it does not have the rest of the information.

I think spring form flushes all the information from the existing bean, re-populates it with the available information and post it to the request, i am not sure how spring form tag behaves, but this is what i can guess.

If this is a real problem, then following are two possible solution i can come to
1. instead of blindly persisting the domain object to db, query the db to get the existing record and do a merge/replace - This approach leads to an extra db call before you persist the data which you had already made before going to editcustomer.jsp
2. Maintain the copy of the domain object on the request at jsp end, and return the same copy along with the spring form created bean and do the merge at the controller end. - Probably not a good idea

Is there any other way you think we can achieve this? Or using spring form tag in this scenario is not a good idea

Thanks
Vinod
 
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
Try making that model a @SessionAttribute

After a successfull submit call Session.setComplete();
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maintain the copy of the domain object on the request at jsp end, and return the same copy along with the spring form created bean and do the merge at the controller end. - Probably not a good idea



Instead of maintaining domain object in request, You should store your domain object in session if you want to avoid a database call and once you are done with updating domain object and persist in database ,remove the object from session.
 
reply
    Bookmark Topic Watch Topic
  • New Topic