Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java EE 6 - JSF Controllers

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

like image 940
Richard Avatar asked Dec 12 '25 15:12

Richard


1 Answers

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.

like image 96
Matt Handy Avatar answered Dec 15 '25 16:12

Matt Handy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!