Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
JSP - A mailing list about Java Server Pages specification and reference
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Subject: Servlet : Session invalidate
Oracle Connection Pooling in 3 2 2
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Subject: Running a Simple JMS Example
Tomcat and webapplication specific java library path
Mapping in workers2 properties
org apache jasper JasperException
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action
   MESSAGE
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
Value attribute of <html:checkbox
url string for connecting jboss to oracle
javax servlet ServletException: BeanUtils populate
5 0 18: Windows XP Pro vs Windows 2000
HTTP Status 404 The requested resource is not available
 
Subject: Re: Inheritance within form beans

Subject: Re: Inheritance within form beans

2007-10-03       - By Rick Reumann

 Back
On 10/3/07, Kothari, Kailash <Kailash_Kothari@(protected)> 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 );
     serviceLayer.doUpdate(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: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)


©2008 junlu.com - Jax Systems, LLC, U.S.A.