Struts - How to filter out only those fields which changed
1 posts in topic
Flat View  Flat View

Posted By:   Madhu_Analakkat
Posted On:   Tuesday, March 25, 2003 11:12 AM

In an 'edit' scenario, where user gets form fields pre-populated she may not change all of the data. In the Action of this update, how will I know what all fields got changed? So that I need to send only those fields to the database? Does struts provide any support for this? If not what is the best way to go about?

Re: Struts - How to filter out only those fields which changed

Posted By:   Christopher_Koenigsberg  
Posted On:   Tuesday, March 25, 2003 01:50 PM

I just did a page where I pre-filled values and let the user edit some of them by clicking a checkbox, for each field, to enable it for editing. e.g. if I had text field "firstName" I also had checkbox "cboxFirstName", and so on.

In Javascript on the client, when a checkbox (say "cboxFirstName") is clicked, I change the "disabled" property to false for the associated text input field ("firstName.disabled"). This lets the user edit the value in the text field. (of course you toggle the state and keep track of the previous state, letting them disable it again etc.)

Over on the server side, when the form is submitted, in the Action, I loop through all the form properties for the checkboxes ("cboxFirstName", "cboxLastName", etc.), looking for non-null, true-valued ones.

Only the checked (enabled) checkboxes are passed as parameters, that's the trick. So for each one I got (each non-null checkbox form property), I knew the corresponding text field had been enabled for editing, hence I got its value, from the corresponding form property.

About | Sitemap | Contact