struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jim Barrows" <jbarr...@sssc.com>
Subject RE: General Action Question
Date Mon, 10 Jan 2005 22:18:21 GMT


> -----Original Message-----
> From: Brandon Mercer [mailto:brandon@eutonian.com]
> Sent: Monday, January 10, 2005 11:06 AM
> To: user@struts.apache.org
> Subject: General Action Question
> 
> 
> Hello Group,
> I'm reading an off the shelf book about DynaActionForms and 
> I've got a 
> question about best practice stuff.  In this book it says 
> that you need 
> to create an Action to work with the info you got much the 
> same as the 
> ActionForm you typically use.  In my previous work I've 
> always just sent 
> the request into my 'data' class to pull info from and send 
> it into the 
> database.  Let me send some code snippets:
>    String action = request.getParameter("action");
>      AssetData.addAsset(request, session, 
> getDataSource(request,"trustmaster"));
> 
> So if I'm sending the request and working with that, is there 
> a need to 
> parse the DynaActionForm using:
> 
>    DynaActionForm lookupForm = (DynaActionForm) form;
>    String symbol = (String)lookupForm.get("symbol");

Yes, in general your data class has absolutely no need to know about a request, so you would
normally copy the ActionForm into a Data Transfer Object, and pass that to your data layer.
So, you would do this:
	DynaActionFrom lookupForm = (DynaActionForm)form;
	BeanUtils.copyProperties( lookupDto, lookupForm);
	AssetData.addAsset( lookupDto);

This allows you to cleanly seperate the UI from your backend code.

> 
> Specifically, I want to know if I'm validating the input in 
> both cases, 

Depends... with the default struts valiation is being done before you get to the action class.


> and inserting the entire request into the database (after I parse out 
> each value) if I need to use the second example to work with 
> DynaActionForms.  I'm using multi-page forms, but I insert the values 
> into the JSP page for each new page in the wizard.  Thanks 
> for any help, 
> as I'm "fresh" with struts. Brandon Mercer
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 

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


Mime
View raw message