detect changes in an object

T

T-Boy

Hello everyone.

I am building a web interface with struts. I have a collection of
objects that are represented on a jsp page and for every object in the
collection, the users can change one or more properties.

Now when the users submit the form that is listing all the objects, I
need a way to detect which objects have been changed and if possible
even which attributes have been changed and also the old value of the
attribute. I can give you an example. Lets say we have a list of
objects that each have an attribute which is a string. Now when the
user submits the form with the list I would like to know: which object
have changed the internal value of the string! and also what the old
values of of the internal attributes was before the change.

Is there any pattern that accomplishes this or is the anybody that has
a good idea on how to solve this!
 
C

Chris Smith

T-Boy said:
Now when the users submit the form that is listing all the objects, I
need a way to detect which objects have been changed and if possible
even which attributes have been changed and also the old value of the
attribute. I can give you an example. Lets say we have a list of
objects that each have an attribute which is a string. Now when the
user submits the form with the list I would like to know: which object
have changed the internal value of the string! and also what the old
values of of the internal attributes was before the change.

Is there any pattern that accomplishes this or is the anybody that has
a good idea on how to solve this!

I see two immediate options:

1. The objects are JavaBeans and implement PropertyChangeEvent. Your
application registers a PropertyChangeListener on the objects, and keeps
track of changes.

2. Your application keeps a cached copy of the objects, and compares the
two once you're done making the changes.

Which you'd go for depends on a number of factors, including relative
knowledge of code modules (i.e., how much should your code know about
the data stored in these objects) and the number of likely changes.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
T

Tim Slattery

Hello everyone.

I am building a web interface with struts. I have a collection of
objects that are represented on a jsp page and for every object in the
collection, the users can change one or more properties.

Now when the users submit the form that is listing all the objects, I
need a way to detect which objects have been changed and if possible
even which attributes have been changed and also the old value of the
attribute.

There's no good way to do this, it's just not something that HTTP
handles. I've done it in my app by having hidden fields that contain
the original values of things that the users may change. When the page
is submitted I decide whether something's been changed by comparing
the possibly changed value with the value from the hidden field.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top