You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Kyle Robinson <KR...@pangaeainc.com> on 2001/04/04 18:01:44 UTC

Dirty flag on forms

Has anyone implemented the concept of a dirty flag on an form in Struts?
For example if the form is changed then a flag is set and if the user wants
to navigate away from that form without "saving" the info changed then they
will get a prompt to save.

Most of this is JavaScript but each element on the form needs to have some
onChange code.  Is there an easy way to do this by iterating over a whole
form?

Ideas?

Kyle Robinson
Systems Consultant
Pangaea Systems Inc.
(250) 360-0111


Re: Dirty flag on forms

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 4 Apr 2001, Kyle Robinson wrote:

> Has anyone implemented the concept of a dirty flag on an form in Struts?
> For example if the form is changed then a flag is set and if the user wants
> to navigate away from that form without "saving" the info changed then they
> will get a prompt to save.
> 
> Most of this is JavaScript but each element on the form needs to have some
> onChange code.  Is there an easy way to do this by iterating over a whole
> form?
> 
> Ideas?
> 

It seems to me you could implement this concept in your ActionForm beans,
along the following lines:

* After the bean properties have been configured the way they will be
  displayed, call a method checkpoint() or something that saves a copy
  of all current property values.

* When the bean is repopulated after being submitted, have your Action
  call a method isChanged() that tested the current value versus the saved
  value for each property, and return true if anything is different.

The above description assumes you store your beans in session scope -- to
use request scope instead, you'd need to include the "original
value" properties in the form (as hidden variables), and have
corresponding properties in the ActionForm bean.


> Kyle Robinson
> Systems Consultant
> Pangaea Systems Inc.
> (250) 360-0111
> 
> 

Craig