File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Determing if Form Data Changed" Watch "Determing if Form Data Changed" New topic
Author

Determing if Form Data Changed

Joe Brigs
Ranch Hand

Joined: Jun 06, 2011
Posts: 60

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
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
Anuj Batra
Greenhorn

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
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

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
Bartender

Joined: Oct 14, 2005
Posts: 18124
    
    8

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
Greenhorn

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: http://aspose.com/file-tools
 
subject: Determing if Form Data Changed
 
Similar Threads
not sure which methods must be synchronized
Constructing Database Update Statements based on html form data
Help with update
How to determine when a form field is submitted if it's changed from the original value?
How to identify changed fields