• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Bear Bibeault
  • paul wheaton
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Mikalai Zaikin
  • Piet Souris
Bartenders:

Struts and App Design question

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
- 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
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok thank you.
 
Kinjal Sonpal
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm .. much clearer. I was also thinking on similar lines.

Thanks and regards,
Kinjal Sonpal
[ May 28, 2004: Message edited by: Kinjal Sonpal ]
 
The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart:
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
reply
    Bookmark Topic Watch Topic
  • New Topic