@SessionScoped bean looses scope and gets recreated all the time, fields become null

You’re using the wrong @SessionScoped annotation. If you’ve registered the bean with the JSF @ManagedBean annotation, then you need to import the @SessionScoped from the JSF (javax.faces) package as follows: import javax.faces.bean.SessionScoped; When you incorrectly use a CDI scope on a JSF managed bean, then there is effectively no JSF scope for the JSF managed … Read more

How can I add FacesMessage during page load? Using @PostConstruct does not seem to work

That can happen when the message component is rendered before the message is added. In your specific example, the bean is referenced for the first time by the <h:outputText> component and thus constructed for the first time at that moment. But the <h:outputText> component appears in your specific example after the <p:messages> component, so the … Read more

When to use f:viewAction / preRenderView versus PostConstruct?

When should one use the f:viewAction or preRenderView event to initialize data for a page verses using the @PostConstruct annotation? Use the <f:viewAction> when you want to execute a method before the HTML is been rendered. This is particularly useful if you want to perform actions based on model values set by <f:viewParam> during update … Read more