You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Molitor, Stephen" <SM...@erac.com> on 2003/01/28 15:30:19 UTC

Copying 'nested' properties from Dyna form to beans

What's the best way to copy 'nested' form property values to Java beans?
For example, let's say I a 'Person' bean, which contains a nested 'Name'
bean, like this:

class Name {
  String getFirstName() {...}
  void setFirstName(String firstName) {...}

  String getLastName() {...}
  void setLastName(String lastName) {...}
}

class Person {
  Name getName() {...}
  void setName(Name name) {...}

  String getZip() {...}
  void setZip(String zip) {...}
}

In the Person class, 'zip' is a top level property, but firstName and
lastName are nested properties of the name property.  I'd like to set up my
validation.xml form element something like this:

<form name="personForm">
  <field property="name.firstName"/>
  <field property="name.lastName"/>
  <field property="zip"/>
</form>

Or, can I / should I nest form elements?

Finally, what I'd like to do is use BeanUtils.copyProperties, or whatever,
to copy from the dyna bean to the Person bean:

  BeanUtils.copyProperties(person, form);

It would be cool if copyProperties would know to copy the name.firstName
form element to person.getName().setFirstName(...).   

What's the best way to do something like this, to copy 'nested' properties
transparently in one method call?  

Thanks!

Steve
  


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>