File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Stuck in presentation tier design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Stuck in presentation tier design" Watch "Stuck in presentation tier design" New topic
Author

Stuck in presentation tier design

Chih-Wei Lee
Ranch Hand

Joined: Feb 20, 2008
Posts: 129
Hi All:
I am working on class diagram and stuck in presentation tier design.
In business and persistence tier, I have design couple of Services and DAOs.
All of them are EJB Stateless Session Beans and I assume DI is used.
So in presentation tier, I have to call the service in Servlet otherwise DI won't work (I don't use JSF cuz I am not familiar with JSF).
It turns out I need to create one servlet for each use case
and a front controller servlet to handle all requests from clients then dispatch to each action servlet to call service EJB.

Is this a good design or bad?

Thanks for your opinion,

Chris

SCEA, SCJD, SCDJWS, SCWCD, SCJP
Dmitri Ericsson
Ranch Hand

Joined: Feb 16, 2010
Posts: 109
I suggest you'd better use JSF, it will eliminate the need of additional controllers, servlets and other stuff. Even if you haven't done projects with JSF the theory you learned in the first part should be enough to design system with JSF. Don't reinvent the wheel, just use best practices


SCEA 5, SCJP 6 My SCEA Experience
Chih-Wei Lee
Ranch Hand

Joined: Feb 20, 2008
Posts: 129
Thank you very much! Dmitri!
I will move to JSF. It's much easier to use JSF with EJB3 to implement MVC.

Thanks
Ionut Bucurescu
Ranch Hand

Joined: Dec 19, 2006
Posts: 68
I would not use a DAO because of the usage of JPA. Do you have any reasons to use DAO?
When using JSF pay attention to avoid having too much framework classes in the diagrams.

Dmitri, by the way, did you displayed in the diagrams the jsf framework classes/components?


SCJP 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA5
Dmitri Ericsson
Ranch Hand

Joined: Feb 16, 2010
Posts: 109
Ionut, From JSF I've displayed only JSP pages connected to controller (I've displayed it as a Controller, but in real life it's FacesServlet) on the class diagram, It's how it is done in the new book, strange solution but i preferred to do according to the book. I didn't show any classes of the framework and not ManagedBeans. However I've included JSFs and managed beans on my sequence diagrams
Chih-Wei Lee
Ranch Hand

Joined: Feb 20, 2008
Posts: 129
The reason why I use DAO is because of the flexibility to replace the data persistence mechanism.
For example, if one day for some reason you can't use the relational database, you can easily switch to another persistence mechanism like XML file. If you inject EntityManager in your service implementation, you won't be able to switch to another persistence mechanism without changing your service implementation.
Dmitri Ericsson
Ranch Hand

Joined: Feb 16, 2010
Posts: 109
Chih-Wei,
DAO may be reasonable in small systems, or to read configuration or in export/import implementations where you sometimes want to export to the database and sometimes to the file.
When it comes to the large enterprise systems, the probability that this system will need to use files instead of database is near to 0. what will be possible is the need of switching database engine (e.g. Oracle instead of DB2), and this will be even easier with JPA, because it has implementations suitable for most of the relational databases.
Ionut Bucurescu
Ranch Hand

Joined: Dec 19, 2006
Posts: 68
Dmitri did you used any design patterns?
Most of them are coming with the frameworks:
jsf-interception filter, front controller, composite view
jpa-value object, value list handler
j2ee-dependency injection

Facade, factory, adapter patterns are good candidate to use with jsf.
Not sure about business delegate, but I guess if you don't have multiple client types(only jsf, maybe also web services) it might not be used.
Dmitri Ericsson
Ranch Hand

Joined: Feb 16, 2010
Posts: 109
Ionut,
In my project I didn't mention any of patterns that come with the framework. I thought that the architecture of a framework and patterns used there is not a part of assignement.

I've used composite view for includng common fragments, Builder and Abstract Factory for object creation, Application Service for common business logic and Proxies when connecting to external systems.
Ionut Bucurescu
Ranch Hand

Joined: Dec 19, 2006
Posts: 68
Thank you very much for the answers!
Chih-Wei Lee
Ranch Hand

Joined: Feb 20, 2008
Posts: 129
Hi Dmitri:
Where do you use Builder and Abstract Factory for object creation?
Do you use it in controller to create object such as Request or Bid, so it can store parameter value and pass to JPA for persistence?

Best,
Dmitri Ericsson
Ranch Hand

Joined: Feb 16, 2010
Posts: 109
Not to reveal assignment details, but my system is designed to build objects and connect substitutable components. I use factories for creating various related components and builder to compose main object from those components. I use them in Application service, which is called from presentation tier, after creation they are persisted with JPA.
Chih-Wei Lee
Ranch Hand

Joined: Feb 20, 2008
Posts: 129
Thanks!!
 
jQuery in Action, 2nd edition
 
subject: Stuck in presentation tier design