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
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.
subject: Using Spring Form tag for Edit Functionality