Hi.. Hmmm.. I do not see why (in the code you came across) one should both populate a form with the properties of the DTO + set the DTO as an attribute on the request object?
It should be enough to populate the form with properties from the DTO. I have seen other solutions where Views (JSPs) always contains a Form tag (eg. form bean). When you populate the form bean from the action you do something like this. pseudo code, action: // Form bean representing the view myFormBean.setVO(myVO); pseudo code, form private MyVOClass myVO; private void populate() { // Call methods to populate form } // Setter that get called from action void setVO(MyVOClass myVO) { this.myVO = myVO; populate(); } The VO could also contain selections for listboxes, comboboxes, etc. So that the VO is View (form) specific, and the DTO (the object/data you really want to store) can be extracted from the VO. You can say that with this approach you have two objects DTO: The object that "travels" across tiers and is persisted, maybe as entity beans or whatever. VO: The view specific object that holds the DTO and what else is needed for generating the view. So the DTO is a subset of the VO. I think is is a nice way to do things, but it introduces yet another object representing the same data. On the other hand it clean separates what data is needed for the generating the view (VO) and what data is needed to be persisted or transferred to antoher tier (DTO). My few cents Regards Henrik ----- Original Message ----- From: "M. Onur Tokan" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, September 22, 2004 5:05 PM Subject: Transfer Data Objects between Actions and Views > Hi, > > I come across the following code. It uses > "request.setAttribute("employee",employeeDTO);" for transfering > employeeDTO. Is it the only practice for doing this? > > -- > Regards, > M. Onur Tokan > > <code> > package net.reumann; > > import org.apache.struts.action.Action; > import org.apache.struts.action.ActionForward; > import org.apache.struts.action.ActionMapping; > import org.apache.struts.action.ActionForm; > import org.apache.commons.beanutils.BeanUtils; > import javax.servlet.http.HttpServletRequest; > import javax.servlet.http.HttpServletResponse; > > public final class InsertEmployeeAction extends Action { > > public ActionForward execute(ActionMapping mapping, > ActionForm form, > HttpServletRequest request, > HttpServletResponse response) > throws Exception { > EmployeeService service = new EmployeeService(); > EmployeeForm employeeForm = (EmployeeForm) form; > EmployeeDTO employeeDTO = new EmployeeDTO(); > BeanUtils.copyProperties( employeeDTO, employeeForm ); > service.insertEmployee( employeeDTO ); > request.setAttribute("employee",employeeDTO); > return (mapping.findForward("success")); > } > } > </code> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]