You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Marco Mistroni <mm...@waersystems.com> on 2004/01/07 11:26:48 UTC
BeanUtils use in struts
Hi all,
I have a question about using BeanUtils in Struts.
For saving me from writing lot of code, I am using DynaActionForms in my
pages.
In the backend, I have some DTOs, so I decided in order to make
My app more 'extensible' without rewriting too much code, to use
BeanUtils to populate my DTOs with values from DynaActionForm, and to
Use the same mechanism to populate DynaActionForm from DTO.
Now, pls correct me if I am wrong, but BeanUtils uses reflection in
Order to populate properties..
I have read from some books ('Effective Java') that using reflection
Is much slower than invoking methods normally..
In my app, I will gain flexibility (I don't need to write methods for
Populating dtos from form and vice versa), but am I going to lose much
In tems of performance?
Anyone can give his comments? I think BeanUtils is of great help,and it
would be a pity to give up the benefits that I get from it...
Best regards
marco
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: BeanUtils use in struts
Posted by "Craig R. McClanahan" <cr...@apache.org>.
Quoting Marco Mistroni <mm...@waersystems.com>:
> Hi Craig,
> Thanx for your comments.
>
> >It uses reflection on POJOs (plain old Java objects) but not on
> DynaBeans ->- the
> > implementation inside DynaActionForm is a HashMap with typesafe
> getters >and
> >setters.
>
> In my case I have a Custom DTO with setter/getters and a Form bean that
> extends DynaActionForm (with properties declared in struts config).
>
> However, BeanUtils.copyProperties() works for calling both
> BeanUtils.copyProperties(form,dto) and
> For BeanUtils.copyProperties(dto, form) ...
>
> Is it supposed to work like that, or is it weird that it's working in
> both
> Ways when I have a DynaActionForm?
>
Yes it is supposed to work that way. Inside the PropertyUtils methods, it looks
at the origin and destination beans individually, and uses reflection (or not)
based on that. So, any combination of POJO and DynaBean works. In addition,
your origin object can also be a Map (although currently the destination cannob
be).
> Thanx and regards
> marco
>
Craig
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: BeanUtils use in struts
Posted by Marco Mistroni <mm...@waersystems.com>.
Hi Craig,
Thanx for your comments.
>It uses reflection on POJOs (plain old Java objects) but not on
DynaBeans ->- the
> implementation inside DynaActionForm is a HashMap with typesafe
getters >and
>setters.
In my case I have a Custom DTO with setter/getters and a Form bean that
extends DynaActionForm (with properties declared in struts config).
However, BeanUtils.copyProperties() works for calling both
BeanUtils.copyProperties(form,dto) and
For BeanUtils.copyProperties(dto, form) ...
Is it supposed to work like that, or is it weird that it's working in
both
Ways when I have a DynaActionForm?
Thanx and regards
marco
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: BeanUtils use in struts
Posted by "Craig R. McClanahan" <cr...@apache.org>.
Quoting Marco Mistroni <mm...@waersystems.com>:
> Hi all,
> I have a question about using BeanUtils in Struts.
> For saving me from writing lot of code, I am using DynaActionForms in my
> pages.
> In the backend, I have some DTOs, so I decided in order to make
> My app more 'extensible' without rewriting too much code, to use
> BeanUtils to populate my DTOs with values from DynaActionForm, and to
> Use the same mechanism to populate DynaActionForm from DTO.
>
> Now, pls correct me if I am wrong, but BeanUtils uses reflection in
> Order to populate properties..
It uses reflection on POJOs (plain old Java objects) but not on DynaBeans -- the
implementation inside DynaActionForm is a HashMap with typesafe getters and
setters.
> I have read from some books ('Effective Java') that using reflection
> Is much slower than invoking methods normally..
> In my app,
Depends totally on what JVM you are using -- the answer changes with every
version. Whether it's visible to you (in terms of increased response time) is
even more variable, but in most web based environments the database is the
primary cause for delays, followed by network traffic. The only way that
reflection can make any difference at all is if you're CPU bound on your web
tier server.
> I will gain flexibility (I don't need to write methods for
> Populating dtos from form and vice versa), but am I going to lose much
> In tems of performance?
>
Depends on your application environment (as described above), but it's pretty
unikely to cause a problem -- especially if you use dynabeans, which don't use
reflection at all :-).
> Anyone can give his comments? I think BeanUtils is of great help,and it
> would be a pity to give up the benefits that I get from it...
>
The only way to know if this matters in your application is to benchmark your
application. But there are thousands of Struts-based webapps in the world,
many using traditional ActionForms (and therefore heavily dependent on
reflection).
Aiming for "fastest possible" is the wrong target. Aiming for "fast enough"
lets you focus on other goals about your app (less code, easier maintenance,
and so on) also.
> Best regards
> marco
>
Craig McClanahan
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: BeanUtils use in struts
Posted by Richard Hightower <rh...@arc-mind.com>.
Reflection has gotten much, much faster than it use to be (JDK1.3 and JDK1.4
made a lot of improvements in speed).
Also consider that a lot of custom tags use reflection already (JSTL, Struts
tags). If you are using JSP, and custom tags than you are already using
reflection all over the place. Also consider that Struts using BeanUtils
internally to populate the ActionForm from the incomming request object.
In the general scheme of things the overhead of BeanUtils is dust on the
scale (for the usage you are talking about).
If you are really worried, use JUnitPerf and create a test that uses
BeanUtils and stress it.
I am sure there are much more effective ways to tune your web application
(like caching semi-dynamic pages and page fragments).
Rick Hightower
Developer
Struts/J2EE training -- http://www.arc-mind.com/strutsCourse.htm
Struts/J2EE consulting --
http://www.arc-mind.com/consulting.htm#StrutsMentoring
-----Original Message-----
From: Marco Mistroni [mailto:mmistroni@waersystems.com]
Sent: Wednesday, January 07, 2004 3:27 AM
To: 'Struts Users Mailing List'
Subject: BeanUtils use in struts
Hi all,
I have a question about using BeanUtils in Struts.
For saving me from writing lot of code, I am using DynaActionForms in my
pages.
In the backend, I have some DTOs, so I decided in order to make
My app more 'extensible' without rewriting too much code, to use
BeanUtils to populate my DTOs with values from DynaActionForm, and to
Use the same mechanism to populate DynaActionForm from DTO.
Now, pls correct me if I am wrong, but BeanUtils uses reflection in
Order to populate properties..
I have read from some books ('Effective Java') that using reflection
Is much slower than invoking methods normally..
In my app, I will gain flexibility (I don't need to write methods for
Populating dtos from form and vice versa), but am I going to lose much
In tems of performance?
Anyone can give his comments? I think BeanUtils is of great help,and it
would be a pity to give up the benefits that I get from it...
Best regards
marco
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org