Rick Reumann wrote:
> Before looking into this struts framework, my controler servlet would
> pass the request object off to the appropriate Action class which in
> turn might hand the request object to another class method that would
> create an EmployeeBean from the request object parameters. Than after
> that EmployeeBean was returned the appropriate method in the business
> logic tier was called such as businessTierObject.addEmployee(
> employeeBean );

Do that, except you can create the EmployeeBean from the EmployeeForm
instead. 

If all the public properties you want to transfer are native types, and
everything has been validated so you know it should convert, you can
just do something like:

 BeanUtils.populate(employeeBean,BeanUtils.describe(employeeForm));

Or, you can do it the hard way, and just call getters inside of setters. 

employeeBean.setProperty(new Integer(employeeForm.getProperty()));

If the properties don't match up exactly, you can used adapter methods
that do whatever transformation is needed. For example, the form may put
formatting characters in the property displayed to the user, but you may
need to strip those out for the database. 

    public void setTelephoneText(String telephone) {
        setTelephone(ConvertUtils.getDigits(telephone));
    }


The databse would use setTelephone() and getTelephone(), a string of
digits, but the form would use setTelephoneText and getTelephoneText,
which format the string for display. The same can go for a property that
needed to be localized, or a non-native type, like Date or Timestamp.

If anyone wants to do more research, and summarize for the group, there
are some starter links on the Newbie FAQ page (under construction,
contributions welcome). 

http://jakarta.apache.org/struts/newbie.html

Something to keep in mind is that there will not be a single best
practice. The ~best~ way to do a lot of these things depends on how the
model is set up. Since Struts is model-neutral, the model can be set up
anyway at all, and the part were the HTTP form data is transferred to
the Model data bean can also be set up anyway at all. Sometimes the
model may be set up to handle conversions from Strings (as ResultSets
and RowSets are), and sometimes you need to do this yourself.

-- Ted Husted, Husted dot Com, Fairport NY US
-- Developing Java Web Applications with Struts
-- Tel: +1 585 737-3463
-- Web: http://husted.com/about/services


Rick Reumann wrote:
> 
> I've just begun studying the struts examples and reading the
> documentation and have waited a bit before I posted this question. I
> am a newbie to struts but have done some searching and looking at
> examples but still need some more help.
> 
> Before I begin it would be best if I ask my questions in the context
> of a simple example. Lets say we have a simple Employee Administration
> application where there might a form that allows you to enter or edit
> employee information.
> 
> Now first off, it would seem likely using struts that I would have an
> EmployeeForm object and then maybe two action objects such as
> AddEmployee and EditEmployee (or possibly just one of them that can do
> all the tasks).
> 
> Now it would seem like for most situations you would have an
> EmployeeForm object and also an EmployeeBean. Now the question I have
> is at what point would you transfer the info in the EmployeeForm
> object to the EmployeeBean? Should this be done in the AddAction and
> then the AddAction might call a method in the business tier of
> doInsert( EmployeeBean employee )? Or do you possibly just pass all
> the form parameters off to a doInsert() method as arguments and then
> in the business tier doInsert() method do what you have to do with
> them.
> 
> I'm having some trouble seeing how they manage this with the
> SaveSubscriptionAction in the strut example. It looks like they are
> using PropertyUtils.copyProperties(subscription, subform); to get the
> information from the subform into a subscription object. (I admit I
> haven't studied using this PropertyUtils objects so I'll have to look
> into it). However, I'm still just generally confused about the best
> way to get the values in my EmployeeForm object which are all Strings
> into the correct format for being entered into a database.
> 
> Before looking into this struts framework, my controler servlet would
> pass the request object off to the appropriate Action class which in
> turn might hand the request object to another class method that would
> create an EmployeeBean from the request object parameters. Than after
> that EmployeeBean was returned the appropriate method in the business
> logic tier was called such as businessTierObject.addEmployee(
> employeeBean );
> 
> The validation abilities using FormObjects seem really powerful, yet
> I'm still stuck on where to do all my casting and conversions of the
> String request parameters into the proper data types (ie..birth date
> as a String to birthDate as a java.util.Date, ss# as a String to an
> int, etc).  I guess my basic question is where should this process
> take place? Do you pass the whole Form object in the Action object off
> to the business tier and let that level deal with creating the correct
> format of the request parameters?
> 
> I'm sure this has all been brought up and/or answered many times so I
> appreciate your patience. Is there a way I can search through past
> posts to this mailing list?
> 
> Thanks for any help.
> 
> --
> 
> Rick
> 
> mailto:[EMAIL PROTECTED]
> 
> "I can't stand cheap people. It makes me real mad when someone says
> something like, 'Hey, when are you going to pay me that $100 you owe
> me?' or 'Do you have that $50 you borrowed?' Man, quit being so
> cheap!"
>   -Jack Handey
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to