开发者

Spring MVC with JSF 2, is this the only way?

All the examples I've seen so far integrating spring/mvc with JSF uses DAO class, DAOImp, Service, Servi开发者_C百科ceImp and then JSF ManagedBean and as far as I know with EJB 3.1 all I need is EJB and JSF ManagedBean. I am not mentioning entities. So based on my understanding with Spring + JSF I need: 5 classes and with EJB + JSF I need only two classes. Please correct me if am wrong but if am right then what's the advantage of using spring with JSF.

Thanks.


You are wrong. -- You can skipp the DAO, DAOImpl and ServiceImpl if you want to implment all in the Service Class.

But even in EJB it is best practice to seperate the Service and the DAOs.

The usage of Interfaces is a kind of style. If you use interfaces, at least you can skip them to and create your services (and Dao) like EJB 3.1 interface free Beans (I don't know the correct name at the moment). At least there are the same pro and cons to use interfaces in Spring and EJB 3.1.

Summary: You can build Spring JSF2 Apps with 2 classes to, but it is best practice to seperate at least JSP (view), Service (EJB's) and DAOs.


comment by Spring or JSF: Ralph please give me an example, suppose I've an entity: Person with id, firstName and lastName what would be the code I need from spring aspect?

In traditonal Spring architecure you have the:

  • Person (Entity) Class -- the one with the @Entity
  • PersonDao - Interface that provides data base Load, Strore, Delete and Find Methods for the Person
  • PersonDaoImpl - implementation of the PersonDao Interface - (@Repository)
  • PersonService - Interface that provides business functionality arround the person, for example a create method that send an email after a person is created
  • PersonServiceImpl - Implementation of the PersonService Interface - it uses for example the PersonDao and other Sevices to provides its functionality (@Service)
  • PersonJSF-Managed Bean - handles the JSF stuff but has no business functionality, it uses the PersonService (or an other Service) to start business functionality

This is one of the most common architecural style (not only in Spring). But even for this there are some variants:

  • how DAO's can be invoked? All Dao Functions must be invoked via the according Service -- or direct
  • DAOs with or whithout Interfaces? (may you need the Interfaces for your Test Mock Framework?) -- (have a look at Hades, there is only the Interface, but in most cases no Impl)
  • Services with or whithout Interfaces? (
  • ...

BTW: one other very intresting architural style, is the one hat Spring ROO uses: It has only the View (PersonController) and the Model (Person), and all DAO and Service Functionality is put in the Model class. -- That is a bit of real OO Design.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜