I did (3) slightly differently - I did
BeanUtils.copyProperties(formBean, Person) in the action, followed by
the Helper stuff. No great difference really. I think that this is
really the only feasible current mechanism for it.
Rick Reumann on 11/05/06 19:13, wrote:
What I ended up doing is
1) A Helper class will generate my String[] conversions to and from a
List of "SomeObject"
2) My form beans stick with String[] properties for multiple
selects/multibox situations
3) Rather than use BeanUtils.copyProperties( myFormBean, Person ) in
my Action, I end up putting two methods in my FormBean...
//PersonActionForm
public void PopulatePerson( Person person ) {
BeanUtils.copyProperties( person, this );
person.setDogs( Helper.populateDogsFromStringArray( this.dogIds ) );
}
public void PopulateFormFromPerson( Person person ) {
BeanUtils.copyProperties( this, person );
this.setDogIds( Helper.populateDogIdsFromDogs( person.getDogs() ) );
}
When inserts or updates are done, all that is needed is typically an
"ID" so what the Helper class methods do in building the List, of say
Dogs, is just build a Dog object with only the ID populated.
Of course the Person object can now still be used for retrievals when
you really want it to contain complete lists of Dogs and Cats (as an
example).
I'm not super happy with the solution, but it works. In other option
was maybe to just stuff some extra String[] array properties into the
value object but that seems sort of lame.
On 5/11/06, Adam Hardy <[EMAIL PROTECTED]> wrote:
This is something for which I've tried to find an elegant solution on
the last couple of projects I worked on.
Using DTO / POJOs from Hibernate for the Person and the Cats and Dogs, I
end up using a sorted set of Cats or Dogs in the page context, which I
then iterate over in the JSP.
This means the taglib for the checkbox / dropdown control points to the
set / collection and names the methods for the label and the value:
<html-el:options collection="${dogList}" property="dogId"
labelProperty="dogName" />
The form therefore has the dogId(s) getter and setter.
However handling the submit where you have to find the Dog pojo with the
chosen ID and place it in the Person.setDog() or Person.getDogs().add()
is frankly complex if not downright ugly (esp if doing deletes!)
There are also issues such as caching of the sets of Cats and Dogs,
limiting the set where business rules apply, and internationalisation.
I intend to develop my caching mechanism soon, and to refactor my ugly
submit helper method to make it handle this juggling of pojos better, so
as you can see I am in the same boat as you.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]