Meaningless Drivel is fun!
The moose likes JSP and the fly likes Determing if Form Data Changed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Determing if Form Data Changed" Watch "Determing if Form Data Changed" New topic

Determing if Form Data Changed

Joe Brigs
Ranch Hand

Joined: Jun 06, 2011
Posts: 70

I have a Form with 30 input fields. The form is intitally populated with Data from a Database and user can update one field or 30.. When the update occurs I have to write one record for every field that the user changed ( Nice DB design , I had no part in it ) Is there a easy way to determine which field was updated ? Or do I have to compare each field in my Servlet to figure this out. ( I use to code in CICS (mainframe) and when we needed to determine if a field changed we would check an attribute flag thats why I asked this question)
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63866

Comparing to the original to see what's changed is the first thing that comes to mind. There is no innate concept of 'changed field' in HTTP.

[Asking smart questions] [About Bear] [Books by Bear]
Anuj Batra

Joined: Sep 18, 2011
Posts: 24
you can use javascript to do this.

on lost focus event of form input fields you can check if the input value is changed.
if yes then set a hidden prameter the specifies the value whether yes or no
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63866

That is a problematic approach as it wil false positive fields that are set back to their original value. If that's not an issue it is one way to approach it but I generally would rather explicitly deal with this on the server rather than implicitly on the client.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

If I recall right, the CICS environment would have had the same possibility of false-positives. However I agree that the straight-forward method of comparing the data sent to the browser with the data coming back from the browser is a good way to go.
Ashish Kataria

Joined: Aug 06, 2011
Posts: 14

The problem lies in not to check if each entry has been changed, but rather, in adding a record for each changed record. If the comparison is not done properly, you might end up in adding records for attribute whose values haven't changed(which is a major back end bug).
And as explained by the marshal..this is the first thing that comes to mind.
I would suggest you to go with the tried and tested traditional way.

Everything's tough until you try your best
-Ashish Kataria,
Software Engineer
I agree. Here's the link:
subject: Determing if Form Data Changed
It's not a secret anymore!