I want to clearly understand the proper way of developing a JSF application.
In our project, the model and controller is the same class, represented by CDI bean. I'm sort of confused whether it's a good practice. As far as I understand MVC pattern, the controller should handle user actions (such as submitting form) and the model should contain business logic and data. Or is it OK, that they are in the same class?
Also, should every page have its own separate Controller/Model (i.e is it considered a good practice)?
It is generally a better idea to have two layers - one with JSF managed beans (might be managed by CDI) and another one with beans that are agnostic of the web framework that is using them.
As for the "controller" - the FacesServlet
can be viewed as the "front controller" for the entire application.
JSF controllers are just UI handlers, they shouldn't carry any business logic. Usually there are even more layers (I include here only layers that relate to logic):
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With