FAQ
As a workaround, you could probably have a base class that overrides writeProperty and checks to see if the new value is the same as the old value before writing? (or a custom superclass template).

Robert
On Mar 11, 2011, at 3/113:14 PM , Michael Gentry wrote:

My particular use case in my Tapestry application is there are many
different pages the user can edit before deciding to save. I wanted
to display an "Unsaved Changes" message as they navigate around from
page to page (combination of JavaScript for the current page and
dataContext.hasChanges() when they move to a new page). However,
Tapestry is always calling the setters when the form is submitted
(page navigation, but not commitChanges()) and this is causing my
"Unsaved Changes" message to always appear, even when they don't
actually change values, because Tapestry has called all the setters
with the original value.

mrg

On Fri, Mar 11, 2011 at 3:54 PM, Andrus Adamchik wrote:
I'd rather we don't introduce a potentially expensive comparison in the superclass setters. A setter may be called many times before a commit, so the assumption is that it is much cheaper to only do comparisons once during commit.

I guess you can generate special setters with a custom template. Or we may run pre-commit logic from within 'hasChanges'...

Andrus


On Mar 11, 2011, at 10:22 PM, Michael Gentry wrote:
I just did a quick test using:

DataContext dataContext = DataContext.createDataContext();

User user = dataContext.newObject(User.class);

user.setFirstName("System");
user.setLastName("Administrator");
user.setUsername("admin");

dataContext.commitChanges();

user.setFirstName("System"); // This isn't a real change

System.out.println(dataContext.hasChanges());

dataContext.commitChanges();

In a nutshell, create a user, commit it, set a value to the same
value, then check hasChanges(). The output is:


INFO: INSERT INTO Users (first_name, id, last_name, password,
username) VALUES (?, ?, ?, ?, ?)
INFO: [bind: 1->first_name:'System', 2->id:200,
3->last_name:'Administrator', 4->password:NULL, 5->username:'admin']
true

The "true" is that the dataContext has changes, even though the second
commitChanges() doesn't do anything (there are no real changes).
Should we modify CayenneDataObject's writeProperty() to check if the
old value and new value are equal before calling propertyChanged()? I
was also noticing Embeddables doing something similar.

Thanks,

mrg

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 5 of 9 | next ›
Discussion Overview
groupdev @
categoriescayenne
postedMar 11, '11 at 8:23p
activeMar 12, '11 at 1:42p
posts9
users3
websitecayenne.apache.org

People

Translate

site design / logo © 2021 Grokbase