3

I'm starting off with Java EE 6 after not touching EE for years (I've been in Spring land for a while).

In JSF 2, am I right in thinking that we don't really have controllers any more. That job is done by managed beans?

If so, is it considered normal practice to then inject a 'Service' class (with CDI) into my managed bean to handle the business logic (and subsequently call DAOs)?

I bought a book (PacktPub's 'EE 6 with Netbeans') and read quite a few tutorials but I'm still a little unclear on how to do it right.

As a bonus question, is there a reference 'PetStore' style app that I can download that shows it all linked together in a best-practices kind of way?

Thanks

Richard
  • 1,731
  • 2
  • 23
  • 54
  • Actually, this tutorial looks really promising: http://jsf-tying-it-all-together.blogspot.co.uk/p/project-1-table-of-contents.html – Richard Apr 20 '12 at 10:44

1 Answers1

3

In JSF 2, am I right in thinking that we don't really have controllers any more. That job is done by managed beans?

It depends on how you define the term controller. Some people confuse managed beans with controllers but they rather belong to the model part of MVC or are located "between" model, view and controller (see this great answer by Arjan Tijms to a similar question).

If so, is it considered normal practice to then inject a 'Service' class (with CDI) into my managed bean to handle the business logic (and subsequently call DAOs)?

This can be done and is normal practice (I do it in all of my projects). But note, that injection does not always work as expected, so for instance you cannot inject a managed bean into a CDI bean (see my answer to a similar question).

As a bonus question, is there a reference 'PetStore' style app that I can download that shows it all linked together in a best-practices kind of way?

You could take a look at the Netbeans tutorials. There you find a lot of information about the topic. A visit to BalusC's blog is also highly recommended.

Community
  • 1
  • 1
Matt Handy
  • 29,855
  • 2
  • 89
  • 112
  • Thanks Matt, some great advice. Will check out that blog over the weekend too. Much appreciated. – Richard Apr 20 '12 at 12:25
  • Sure this is old news to most people but I've just stumbled upon 'Duke's Bookstore' which is part of the Java EE 6 Tutorial. Has a lot of useful examples. – Richard Apr 22 '12 at 22:04