—but, and you can see where this is leading, validateForSave() doesn't get called unless the password is actually changed (assuming nothing else on the User is changed), so I don't get to throw that exception I stashed earlier. In that case I might be
able to make the change to the too-short string, and do what I was planning, but the changePassword() method is another story.
Say changePassword() is called, but oldPassword doesn't hash correctly. Now what? Do I call setPlaintextPassword(newPassword) anyway to ensure validateForSave() is called? But then in that method, I throw the exception I stashed, sure, but the password
has now _changed_ even though the app reports it _hasn't_. So a subsequent call to changePassword() with the previous oldPassword value is going to fail. Again, naively, I considered maybe changing it _back_ to the snapshot value for that attribute in validateForSave()
before throwing the exception, but then BAM! EOF Commandment #4:
Don't modify any EO properties in validateFor...(...) methods
So I'm stumped. Does this sound possible, or should I give up and continue to handle this kind of thing outside the regular validation system?
That is probably your best bet, or have changePassword throw validation exceptions, and accumulate them and any from takeValues in the GUI layer. That way you don’t even call saveChanges() if things have not validated to that point. My presentation from
WOWODC 2009 might give you some ideas. No, of course I never finished it!
There are no files, you have to clone the repository.