You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Hookom, Jacob" <Ja...@redline.mckhboc.com> on 2003/06/23 17:58:39 UTC

RE: Where to do TextConversion?

Your ActionForms should never be passed to your DB layer... ActionForms
should have strict String attributes and in your Action, take care of
mapping your Business Beans to your ActionForms and visa versa-- two
similar, but separate objects.  PropertyUtils works nicely.

Jacob

-----Original Message-----
From: Aaron Longwell [mailto:listservs@newmedialogic.com]
Sent: Monday, June 23, 2003 11:00 AM
To: Struts-User
Subject: Where to do TextConversion?


Struts Users,

I'm adding some currency fields to an ActionForm in struts. The data is 
stored as float in the database. I'm wondering where to do conversion 
between a "$6.70" that's displayed to the user on the form, and the 6.7 
that's stored in the database. Should I use the java.util classes in the 
Action? Or should I add a:

setPrice(java.lang.Float)
getPrice java.lang.Float()

to the ActionForm... and handle conversion within the ActionForm methods?

I may be suffering from a case of the Mondays... but I can't seem to 
think which would be better or more appropriate. I am nearly finished 
with this, my first Struts project.

Thanks,
Aaron


---------------------------------------------------------------------
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


Re: Where to do TextConversion?

Posted by Aaron Longwell <li...@newmedialogic.com>.
I'm not really considering sending  the action form to the db tier.

I am using Strings for all properties in the ActionForm.... I'm 
considering adding getter methods to the ActionForm to clean up the code 
in my Action.

PropertyUtils is a Struts class, right?
Will it do currency text->float conversion of properties?

Thanks,
Aaron

So I can do:

BusinessObject.setPrice(form.getPrice())

Hookom, Jacob wrote:

>Your ActionForms should never be passed to your DB layer... ActionForms
>should have strict String attributes and in your Action, take care of
>mapping your Business Beans to your ActionForms and visa versa-- two
>similar, but separate objects.  PropertyUtils works nicely.
>
>Jacob
>
>-----Original Message-----
>From: Aaron Longwell [mailto:listservs@newmedialogic.com]
>Sent: Monday, June 23, 2003 11:00 AM
>To: Struts-User
>Subject: Where to do TextConversion?
>
>
>Struts Users,
>
>I'm adding some currency fields to an ActionForm in struts. The data is 
>stored as float in the database. I'm wondering where to do conversion 
>between a "$6.70" that's displayed to the user on the form, and the 6.7 
>that's stored in the database. Should I use the java.util classes in the 
>Action? Or should I add a:
>
>setPrice(java.lang.Float)
>getPrice java.lang.Float()
>
>to the ActionForm... and handle conversion within the ActionForm methods?
>
>I may be suffering from a case of the Mondays... but I can't seem to 
>think which would be better or more appropriate. I am nearly finished 
>with this, my first Struts project.
>
>Thanks,
>Aaron
>
>
>---------------------------------------------------------------------
>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
>
>
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: nested objects in ActionForm [was: Where to do TextConversion?]

Posted by Dan Allen <da...@mojavelinux.com>.
A comment was made a few days back that this dicussion (of DTOs vs
ActionForms) comes up every two weeks.  I think this is for 2
reaons.  The first is that it is clearly the most confusing part of
Struts.  Second, I don't think there is a single definitive example
of this yet.  I believe that Matt Raible's appfuse is very close,
yet it doesn't have an example of all the basic cases just yet.  In
short, it would be nice to see an example of a nested ActionForm
using struts nested extension and a form which accepts a date input.

Another comment was that
http://www.mycgiserver.com/~andrej/technical/struts/struts.jsp
seemed like a nice solution.  I agree and disagree.  I agree because
it definitely handles things how they should be handled but I
disagree because it already exists, and it is
BeanUtils.copyProperties.  You can register any convertor you want
with BeanUtils and therefore the framework is already in place.

So onto my question.  Matt, you mentioned that you only use
UserFormEx (or an extended version of your String version of your
DTO) when you have indexed properties, custom validation or the need
for a reset() method.  Would you agree you would also need one if
you had a time input and a date input and you wanted to a get method
which retrieved a datetime object?  I would assume you would have
two fields in the form, time and date, and then the get method on
the ActionForm would combine these two to produce a parsable date
which the convertor could handle.  Does that make sense?

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <da...@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
It is not enough to succeed.  Others must fail.  
 -- Gore Vidal
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


nested objects in ActionForm [was: Where to do TextConversion?]

Posted by Dan Allen <da...@mojavelinux.com>.
Hookom, Jacob (Jacob.Hookom@redline.mckhboc.com) wrote:

> Your ActionForms should never be passed to your DB layer... ActionForms
> should have strict String attributes and in your Action, take care of
> mapping your Business Beans to your ActionForms and visa versa-- two
> similar, but separate objects.  PropertyUtils works nicely.
> 
> Jacob

I want to branch off here with a question regarding this statement.
If ActionForms should have strict String attributes and the Action
transfers data from the DTO to the ActionForm making use of
Converters where necessary, how are nested objects handled?  Say for
instance there is an Employee object and that employee works for a
Company.  Most of the get/set methods would be strings such as
first/middle/last names and title, but then the employee would need
a nested Company object (struts nested extension comes to mind).
However, would this nested object be a CompanyForm to complement the
EmployeeForm or would it be the Company DTO?  Additionally, how
well does BeanUtils.copyProperties handle nested objects?

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <da...@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
"When you're raised by the Jesuits, you become either obedient 
or impertinent" 
 -- Jack McCoy, "Law and Order"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org