Good day
I am creating my first JSF based application. I am using:
- Wildfly 11
- PostgreSQL
- Maven based project
- IntelliJ Ultimate 2017.3
- CentOS 7.4
- Apache Shiro
- Primefaces 6.1
The model portion of the application is the easy part as it is entities generated from the database using IntelliJ Ultimate's auto schema generation.
I am very confident using JPA and the @PersistanceContext to create an entity manager and use JPSQL.
The xhtml files using JSF tags and the EL language creates the front end and together with a @ViewScoped backing bean forms the view.
Where I am confused about is what should the controller portion consists of?
A problem I seem to frequently run into is getting null pointer exceptions and other errors related to backing bean methods when variables used in these methods have not been properly initialized, especially lists that have to be retrieved from the database using JPA where parameters used in the em queries still needs to be set in the form (but the forms fail to display due to uninitialized variables).
So, I have a questions, and would really appreciate enlightenment.
- How do I prevent these null pointer exceptions?
- If all the DB 'stuff' is moved to 'controller' beans, and the view backing beans only call the methods in the controller beans, will this eliminate my null pointer exceptions?
- What must (according to best practices) a view backing bean contain?
- What must (according to best practices) a controller bean contain and be responsible for?
Any advice would be most appreciated.