Hey all,
The subject should hopefully explain it.. basically, I have to know when any of my several form fields have actually changed. Typically you use some sort of POJO form object and load it up with data to display on a page, and if the form is submitted, within the action class it gets the object and auto-populates it, so that by the time your action method is called, the updated values (if any were changed by the user) are already in the object. However, I have to take any changed values and send them to another server, so I am trying to think of the best way to figure this out. To add a little twist to this.. in an effort to avoid multiple objects of "similar" fields being created with a bunch of copying of get/set methods being done to take the form input and put it into say, an entity bean, I've got a nice way of combining all this into one object (DTO really) so that the
STruts form auto-populates my model pojo, which is then passed to the entity bean as a backing model.. thus using just one object in memory from the front tier to the back. This poses a problem though with my current question.. how do I tell when any form field has been modified so I can collect all the changed values?
I've basically come up with two ways. One is to provide a super class that contains a list of changed fields, and in the setter methods of each pojo model, simply adding to this list either the changed data or some indicator of the field name or something. The other way is to build struts pojo form objects, use those in the action classes, and then copy the values to the entity beans directly (or to a DTO that is passed to the
ejb tier), and simply try a compare on every single field for every request. I am leaning towards some way to flag each field change within the setter methods during auto-population however, since that seems to me to be the best place/time to do it and also avoids me having to use 2ndary objects and run compares on every object/field and copying the objects to entities, etc.
Would love to hear how some of you may determine when a field actually changes from its original value during a user editing some data like profile data.
Thanks.