struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kothari, Kailash" <>
Subject RE: Inheritance within form beans
Date Wed, 03 Oct 2007 22:23:05 GMT
Ok, that's quite interesting..

I think I just need to find a efficient way of doing the deep copy
because my parent class has thousands of attributes in all including
nested attributes..

Thanks ! 

-----Original Message-----
From: Rick Reumann [] 
Sent: Wednesday, October 03, 2007 2:37 PM
To: Struts Users Mailing List
Subject: Re: Inheritance within form beans

On 10/3/07, Kothari, Kailash <> wrote:
> Thanks a lot Rick. That gives me a new area to explore.
> The BeanUtils method - BeanUtils.copyProperties(Object target, Object
> src) - does give me a shallow copy of an object, Im trying to figure 
> out how to get a deep copy..

I might be the only one that does this, but I have all my form beans
extend an abstract  BaseActionForm that has these two methods:

public void populateValueObject(Object obj) throws
IllegalAccessException, InvocationTargetException {
		 BeanUtils.copyProperties(obj, this);
	public void populateForm(Object obj) throws
IllegalAccessException, InvocationTargetException {
		 BeanUtils.copyProperties(this, obj);

The default behavior is nothing interesting - for example in a
setUpFormForEdit method in an Action:

public ActionForward setUpFormForEdit(...) {
      EmployeeForm eForm = (EmployeeForm)form;
      Employee employee = serviceLayer.getEmployee(someID);
      eForm.popluateForm( employee );

Similar thing on the way out   :

public ActionForward doEdit(...) {
      EmployeeForm eForm = (EmployeeForm)form;
      Employee employee = new Emloyee();
      eForm.populateValueObject( employee );

Where it becomes more interesting is when you have cases where BeanUtils
can't do everything. For example, I've had cases where if certain items
in a form were checked, it would alter what I do the resulting
ValueObject and same thing the other way.  In a more common sense,
sometimes people might have a form with a month, date, and year form
fields but ultimately your value object just needs a single "date."  I
found it nicer in these cases then to just override those base class
methods and make sure my form and value object is populated correctly
there instead of doing all that mess in my Action class.

In your case this is where you'd do your deep copy stuff....

YourCustomActionForm extends YourBaseBeanActionForm {

public void populateForm(Object obj)   {
         //maybe first get a base shallow copy of some things
         //BeanUtils.copy or call super.populateForm(obj)

         //now do your custom deep copy stuff as needed }

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message