I have read a lot of discussion on forms best practices in the list archives, but I have some questions that I don't think have been addressed:

1. PropertyUtils.copyProperties() only performs a shallow copy, according to it's JavaDoc description. So I think this means that the form properties with nested objects could be referring to the same object instance that is actually one of the properties of a business object. Now, doesn't that mean that business objects are being modified without being mediated by the Action object? In other words, you don't get the chance to look at the input data and decide whether or not to reject it or use only some of it to change the state of the model.

2. If the scope of an ActionForm is "request", then even if you pre-populate it before displaying a form to the user, it's data will be gone when the user submits the form (because it's a new instance). So if you have properties with nested values they cannot be set on form submission, because the parent property no longer exists. Isn't this a common problem, or is it just me?

For example, I have a Map-backed ActionForm that has a variable set of fields, each with nested properties, determined at runtime. When I submit the form, if it's request-scoped, those nested properties can't be set because the map is now empty.
eg: the property "value(dynamicItem).name" can't be set, because it requires a call to MyForm.getValue("dynamicItem").setName() -- but MyForm.getValue("dynamicItem") returns null because the map is now empty.
Do most people use session-scoped forms for this? then what if the user has two windows, and decides to show use the same form to edit different records in each?

A potential solution:
I'm kind of torn over whether I think this is a good idea or not, but I wrote a wrapper object that I'm using as a general value object. it solved both problems because 1) it uses recursive calls to PropertyUtils.copyProperties() to create a "deep" representation of the original (business) object using Maps and Lists (and String or Boolean as the "leaf" datatypes). and for problem 2) it returns a new (empty) instance when asked for a property that doesn't exist. so getValue("dynamicItem").setName() always works, even if there is no value for the key "dynamicItem".

Now is somebody going to tell me that was a waste of time because there are simple answers to the two questions above? I hope so, because it would be nice to simplify, and this might be a bit slow. What do you think? I would appreciate any input.

However I end up doing it, I don't want to write many ActionForm classes, I want to use one flexible one in all (or at least most) cases, and I want to be able to dynamically create copied representations of my business objects that can be used as form properties without having to manually code a String-and-Boolean-only value object for each business object. call me lazy, but I don't think there's any disadvantage in doing the view component totally dynamically.

thanks!


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to