Scott Van Wart wrote:
We have a requirement that the user be prompted if any changes have been
made on a form, and they try to navigate away. I've divided this up
Firstly, is the requirement to detect changes to the form compared to
how it was last rendered, or compared to how it was *originally*
rendered? I.e. do you have to be able to detect a difference in form
state across multiple requests?
into sub tasks:
- Iterating through properties of a bean.
- Render properties as hidden fields.
- Render some JavaScript to check for modifications.
The last one's going to be the tough one, but it's manageable. Before I
start writing some custom tags, I was wondering if Struts or its
dependent libs had any of this functionality already. I'd likely need
some type of property class, and a way of discerning, in JSP tags
(preferable), if a property is nested, a collection, a boolean or a
string. I think those four types should cover it. I've no problem
writing the facility myself but I'd hate to duplicate work that's
already there.
I'm not aware of any existing solution for this (though there may well
be solutions out there), but it sounds like you're over-complicating things.
First, you can detect if any field in a form has changed without having
reference values to compare against, provided you only need to know if
they've changed since the form was rendered. The browser keeps track of
that, so all you need to do is iterate through all form fields and query
each one to find out if it's changed.
If the form might be submitted and redisplayed one or more times before
final submit, and you want to compare the current state against the
original state (before any submit and redisplay), *then* you'll need a
way to represent the starting state of the form, and make your
comparison against that.
Even then, all you really need is a Javascript object containing
key/value pairs describing each form property's starting value. You
shouldn't need to worry about server-side data types, collections, or
anything else; just 'form field X has value Y'.
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]