aspose file tools*
The moose likes Struts and the fly likes Struts and App Design question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts and App Design question" Watch "Struts and App Design question" New topic
Author

Struts and App Design question

Kinjal Sonpal
Ranch Hand

Joined: Jun 06, 2003
Posts: 96
Hi all,

I'm having a typical mid-size (having around 35-40 pages) web project. For this I'm trying to follow MVC, though not sure. I'm having DAO -> Business layer -> Struts layer kind of flow.

Most typically, the business layer (shall I call it service layer?) APIs are called from the struts Action classes (I'm using DispatchAction at most places). So a typical method in DispatchAction does something like : Fetch x from AManager, fetch y from BManager, process inputs, put them in ActionForm instance, pass it on to jsp.

My question : Is this a decent approach to manage things? Since the project has only implemented one small section, if required, I can still manage to refactor things. Since this is my first real world struts project, I'm feeling a little shaky.

Please share your thoughts on this.

Thanks and regards,
Kinjal Sonpal
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
It sounds like you are on the right path. Just to restate, here's the typical (abbreviated) flow.

1. User submits an HTTP request

2. Struts Action pulls necessary data from the HTTP request, ing business objects (BOs), and calling BO methods with data from the request as necessary.

3. BOs call DAOs, which in turn access the datastore, returning the data to the BO, possibly as a DTO (data transfer object).

4. BOs return data to the Action (possibly as a DTO), which then either places the data in scope or copies it to an ActionForm as needed. The Struts ActionServlet then forwarding to the JSP specified in the Action.

5. JSP accesses data in scope and displays it for user.

HTH
Saritha Penumudi
Ranch Hand

Joined: Aug 18, 2003
Posts: 147
Hi I have few queries in the process defined.

1. User submits an HTTP request
- clear

2. Struts Action pulls necessary data from the HTTP request, ing business objects (BOs), and calling BO methods with data from the request as necessary.
- Does the Action class send data through method parameter of the business object or we will have a valueObject that is accessible through all the layers of the application. By valueObject I mean a java class with setter and getter methods to which Action class would populate data.
- What is the best process to use?

3. BOs call DAOs, which in turn access the datastore, returning the data to the BO, possibly as a DTO (data transfer object).
- What are DAO's. Can we say DAO as an entity bean?.
- Can we say DTO as ValueObject which i have refered above?.
- if DAO is termed as entity bean then i think BO should build the DTO from the enitity bean. Please correct me if my understanding is wrong.

4. BOs return data to the Action (possibly as a DTO), which then either places the data in scope or copies it to an ActionForm as needed. The Struts ActionServlet then forwarding to the JSP specified in the Action.
- assuming DTO as a valueObject.

5. JSP accesses data in scope and displays it for user.
- clear

Thank you very much
Saritha
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
- Does the Action class send data through method parameter of the business object or we will have a valueObject that is accessible through all the layers of the application. By valueObject I mean a java class with setter and getter methods to which Action class would populate data.

Your choice.

- What is the best process to use?

There isn't necessarily a best way. The "best way" is determined by your application.


- What are DAO's. Can we say DAO as an entity bean?

See DAO Pattern. An entity bean is not a DAO. If you are using EJB's, then the Struts Action would likely call some Business Delegate which would in turn access your EJBs.

- Can we say DTO as ValueObject which i have refered above?.

Value Objects and Data Transfer Objects are often used interchangebly. There are some semantic differences, but for all intents and purposes you can think of them as the same.

- if DAO is termed as entity bean then i think BO should build the DTO from the enitity bean. Please correct me if my understanding is wrong.

If you're speaking strictly DAO, as per the link I gave previously, then the DAO builds the DTO (VO) and returns it to the business object. Your architecture may differ though.
Saritha Penumudi
Ranch Hand

Joined: Aug 18, 2003
Posts: 147
Thank you very much for providing link on DAO design pattern.
It was very useful.

Thank you for clearing my queries.

Saritha
Saritha Penumudi
Ranch Hand

Joined: Aug 18, 2003
Posts: 147
Hi,
In the DAO design pattern it is mentioned that CMP are not usually used with DAO bcoz container does work of a DAO.
It also mentioned that DAO can be used with CMP.
I wanted to know in what scenarios the CMP would like to use DAO and how we would configure this in Deployment descriptor.

I would appreciate is you could give me some example.

Thank you very much
Saritha
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
Originally posted by Saritha ventrapragada:
Hi,
In the DAO design pattern it is mentioned that CMP are not usually used with DAO bcoz container does work of a DAO.
It also mentioned that DAO can be used with CMP.
I wanted to know in what scenarios the CMP would like to use DAO and how we would configure this in Deployment descriptor.

I would appreciate is you could give me some example.

Thank you very much
Saritha


I recommend you ask this question in the EJB forum.
[ May 26, 2004: Message edited by: Jason Menard ]
Saritha Penumudi
Ranch Hand

Joined: Aug 18, 2003
Posts: 147
Ok thank you.
Kinjal Sonpal
Ranch Hand

Joined: Jun 06, 2003
Posts: 96
Hey, that is a great discussion. I'm much more confident now after reading all that.

I have one more question. What is the general strategy adapted to managing and declaring Exceptions. For data related failures, how the DAOs inform the BOs? I guess, the BOs would also have to inform the Actions.

Please also share your thoughts on this.

Thanks and regards,
Kinjal
[ May 27, 2004: Message edited by: Kinjal Sonpal ]
Mathur Neni
Ranch Hand

Joined: May 10, 2004
Posts: 33
The exceptions that are raised in DAO's can be categorized based on your application needs, and better to make sure some hierarchy defined.

In the BOs you can get the exceptions received, you can have as many exceptions defined (container exceptions, sub application exceptions, other exceptions...etc.,)

When it comes to action classes, I feel that there should be one kind of generic predefined application exception that should be thrown. Anyway that generic exception is going to carry a key, which should be picked up from message resources file.

Does this give any picture?
Kinjal Sonpal
Ranch Hand

Joined: Jun 06, 2003
Posts: 96
Hmmm .. much clearer. I was also thinking on similar lines.

Thanks and regards,
Kinjal Sonpal
[ May 28, 2004: Message edited by: Kinjal Sonpal ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts and App Design question
 
Similar Threads
Design of Exception Handling in Enterprise System.
Values in Struts JSP page
struts DAO layer and DTO objects
struts DAO layer and DTO objects
Questions regarding the DAO pattern