You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jim Barrows <jb...@sssc.com> on 2004/09/08 01:03:36 UTC

RE: Confusion in Classes


> -----Original Message-----
> From: Tom Holmes Jr. [mailto:tom@tomholmes.net]
> Sent: Tuesday, September 07, 2004 4:04 PM
> To: Struts Users Mailing List
> Subject: Confusion in Classes
> 
> 
> I'm still a Struts newbie, but I have some confusion on the amount of 
> classes I need to use in order to create a CRUD application.
> 
>  From what I can see I need a "form bean" in order to capture 
> the data 
> from the JSP page.  This contains the validate method which 
> would verify 
> some of the data from the JSP page.  I also need an "Action" 
> class/servlet that captures the action ... so if I had Add, 
> Update, or 
> Delete button, the Acttion class/servlet would handle the action.
> 
> Now, there is also the "bean" itself sometimes which has a 
> 'DTO' in the 
> name.  I guess this is for "Data Transfer Object" which handles the 
> create, retrieve, update, and delete database actions.
> 
> So, I'm a little unsure about the whole sequence of actions within 
> struts, but here is what I want to do when I add a record.

0) Instaniate the form bean, if not already existing.
0.1) transfer request params to form bean
0.2) validate form bean by calling validate
0.3) If errors, return to page indicated by input in the action mapping, otherwise keep trucking.

> 1) calls the action class/servlet execute method
XXXXXXXXXXXXXX> 2) calls the formbean class so it can validate if the data is ok
XXXXXXXXXXXXXX> 3) if there are errors return to the page configured in struts
XXXXXXXXXXXXXX> 4) if there are NO errors

>     a) then instantiate the DTO class (so we can update the database)

3) Copy relevant fields from form to VO/DTO performing parsing as needed.

XXXXXXXXXXXXX>     b) Instantiate the form itself which contains data we got 
XXXXXXXXXXXXX> from the 
XXXXXXXXXXXXX>   JSP page
XXXXXXXXXXXXX>     c) pass in the "formbean" into the DTO class, so we can 
XXXXXXXXXXXXX> transer the 
XXXXXXXXXXXXX> data to the DTO from the "formbean"
>     d) call the insert method within the DTO class to file 
> the data to 
> the database

DAO instead of DTO maybe?

>     e) if there is an error, then we should return false to 
> the action 
> class so we can take the action as defined in the 
> struts-config.xml file.

No.  Return the appropriate forward, usually failure, but could be more specific so struts can find the url to head to.  You could also just throw the exception on out, and handle it with the struts exceptionhandler.

> 
> If this is correct, or sort of correct, please let me know so I can 
> adjust my thought process.   Thanks for any information you 
> can provide.

Your welcome... helps to run things in debugger and trace things through.

> 
> Thanks.
> 
>                          Tom
> 
> ---------------------------------------------------------------------
> 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


Re: Confusion in Classes

Posted by "Tom Holmes Jr." <to...@tomholmes.net>.
 From what Erik Weber was saying the DTO is almost like the "form-bean" 
except that the "form-bean" contains mostly strings because it is data 
from the JSP web-page form, and the DTO will hold the information that 
it gets from the database, so it will have ints, strings, booleans, 
dates etc.

I think you and Erik Weber said the same thing: Use a DAO class, and 
have 4 public methods: create, retrieve, update, and delete and then 
pass in the DTO to the DAO class.  The DAO class will have all the 
database connections, and the DTO simply holds the database model of the 
data.

Is that correct?  I think I was incorrectly combining the DAO and DTO 
classes into one class.  If I was getting the data from anywhere else, 
the I'd still be able to use the DTO and DAO classes seperately to file 
data.

I think that is what through me.  So, for the user example I'll need:
--UserForm form-bean to hold the string data from the jsp web-page form
--UserAction to determine what we action we are doing (C.R.U.D.)
--UserDTO to hold the ints, strings, booleans, dates, etc from the 
database and maybe any business logic pertinent to the user
--UserDAO to handle the data transfer to/from UserDTO to/from the database

I think I am getting.   Thanks for the help, It is much appreciated!

                   Tom


Jim Barrows wrote:

> 
>>-----Original Message-----
>>From: Tom Holmes Jr. [mailto:tom@tomholmes.net]
>>Sent: Tuesday, September 07, 2004 4:04 PM
>>To: Struts Users Mailing List
>>Subject: Confusion in Classes
>>
>>
>>I'm still a Struts newbie, but I have some confusion on the amount of 
>>classes I need to use in order to create a CRUD application.
>>
>> From what I can see I need a "form bean" in order to capture 
>>the data 
>>from the JSP page.  This contains the validate method which 
>>would verify 
>>some of the data from the JSP page.  I also need an "Action" 
>>class/servlet that captures the action ... so if I had Add, 
>>Update, or 
>>Delete button, the Acttion class/servlet would handle the action.
>>
>>Now, there is also the "bean" itself sometimes which has a 
>>'DTO' in the 
>>name.  I guess this is for "Data Transfer Object" which handles the 
>>create, retrieve, update, and delete database actions.
>>
>>So, I'm a little unsure about the whole sequence of actions within 
>>struts, but here is what I want to do when I add a record.
> 
> 
> 0) Instaniate the form bean, if not already existing.
> 0.1) transfer request params to form bean
> 0.2) validate form bean by calling validate
> 0.3) If errors, return to page indicated by input in the action mapping, otherwise keep trucking.
> 
> 
>>1) calls the action class/servlet execute method
> 
> XXXXXXXXXXXXXX> 2) calls the formbean class so it can validate if the data is ok
> XXXXXXXXXXXXXX> 3) if there are errors return to the page configured in struts
> XXXXXXXXXXXXXX> 4) if there are NO errors
> 
> 
>>    a) then instantiate the DTO class (so we can update the database)
> 
> 
> 3) Copy relevant fields from form to VO/DTO performing parsing as needed.
> 
> XXXXXXXXXXXXX>     b) Instantiate the form itself which contains data we got 
> XXXXXXXXXXXXX> from the 
> XXXXXXXXXXXXX>   JSP page
> XXXXXXXXXXXXX>     c) pass in the "formbean" into the DTO class, so we can 
> XXXXXXXXXXXXX> transer the 
> XXXXXXXXXXXXX> data to the DTO from the "formbean"
> 
>>    d) call the insert method within the DTO class to file 
>>the data to 
>>the database
> 
> 
> DAO instead of DTO maybe?
> 
> 
>>    e) if there is an error, then we should return false to 
>>the action 
>>class so we can take the action as defined in the 
>>struts-config.xml file.
> 
> 
> No.  Return the appropriate forward, usually failure, but could be more specific so struts can find the url to head to.  You could also just throw the exception on out, and handle it with the struts exceptionhandler.
> 
> 
>>If this is correct, or sort of correct, please let me know so I can 
>>adjust my thought process.   Thanks for any information you 
>>can provide.
> 
> 
> Your welcome... helps to run things in debugger and trace things through.
> 
> 
>>Thanks.
>>
>>                         Tom
>>
>>---------------------------------------------------------------------
>>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
> 
> 


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