I have had to do similar things but took a different approach.
First I assumed users will not always be nice. They will sometimes use
the back button, sometimes close the browser, etc.
Second, I don't want to keep un-applied changes around (so in a
list-detail view, the list shouldn't show changes until the details
are saved)
My solution, was instead of keeping the old values around, was to
always work on a clone.
So, when the user runs an edit() action, I clone the object from the
list to edit. The user works on that object for a while, and either:
(1) saves, (2) cancels or (3) leaves the page
In the case of (1), I save the changes to the database, and then update the list
In the case of (2), I simply throw the clone out (equivalent of clear.
If you wanted to reset and keep editing, just generate a new clone)
In the case of (3), the clone just sits around until my Seam
conversation is GC'd or the user starts editing a new item (in which
case the clone is recreated, overwriting the old clone)
Thought I would mention in case that is the business logic/page flow
you are trying to achieve.
-Andrew
On 8/1/06, Mike Kienenberger <[EMAIL PROTECTED]> wrote:
On 8/1/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> I want to be able to reset an update form to it's initial state. Sounds
> simple enough, but...
For what it's worth, I handled this by creating a "public String
clear() { return "clear"; } action method and a
redirect-back-to-the-same-page navigation rule.
<navigation-rule>
<from-view-id>/pages/mypage.xhtml</from-view-id>
<navigation-case>
<from-outcome>clear</from-outcome>
<to-view-id>/pages/mypage.xhtml</to-view-id>
<redirect />
</navigation-case>
</navigation-rule>
I don't really like it, but resetting all of the page backing been
values to null in an action wasn't working, and I didn't want to spend
the time to track down why.
(You can use use action="clear" and skip the java code, but I have my
commented-out java-based clearing code in there still.)