Rafael Taboada wrote the following on 7/11/2005 6:28 PM:
Thanks, I got it!...
I needed to save the errors :)
Rick Thanks for ur advice about using another class to manage JDBC... I'll
review that... Do u know any samples about how to do that?..
Well typically I like to use the container managed connection pool. (If
using Tomcat they have pretty simple docs on it.) The point is though to
simply move that to another class. At the very least you'll want one
other layer (typically a DAO layer) that takes care of doing your CRUD -
-create,remove,update,delete stuff. This DAO layer is where you'd do the
DB/JDBC stuff or if using something more slick like iBATIS/hibernate
those call would do there also. So for an example updating an Employee
//In Action method:
execute(...) //or dispatchMethod update(..) {
//cast to your ActionForm of String properties
EmployeeActionForm eForm = (EmployeeActionForm)form;
//business POJO with correct Data types
EmployeeVO emp = new EmployeeVO();
//easy to take the stuff from ActionForm to VO
BeanUtils.copyProperties( emp, eForm );
//Do the update
yourEmployeeDAO.updateEmployee( emp );
}
I typically have one more layer before the dao, that I usually call a
Service or Delegate (not using correct Design pattern terms I'm sure:)
But anyway this way you can do several other business logic things and
it even hides the dao part. So for example maybe besides doing an update
to the DB you also needed to call an API to send out some e-mail
notifications. This stuff I'd do in the service class...
//YourService
updateEmployee( EmployeeVO emp ) {
//do the update
yourDAO.updateEmployee( emp );
//do some stuff or maybe some logic
//like send out an email
}
//IN your Action it just changes from calling DAO to calling service
yourService.updateEmployee( emp );
If you take the above approach you'll keep your Actions pretty clean and
easy to read and understand. Of course you might do some other stuff not
shown the Action above like saving success messages, calling validation,
saving some errors, some slight forwarding logic, etc. Point is to keep
them clean though. If you aren't careful you'll end up with your Action
classes doing too much business oriented tasks that can be better pushed
off to another class.
--
Rick
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]