Search code examples
jsfview-scopepostconstruct

@PostConstruct method of @ViewScoped bean is called two times on page refresh


I have a bean called indexBean and it has an init method. My bean is set to be ViewScoped.

@PostConstruct
public void init(){
    ...
    System.out.println("entered");
    ...
}

Why the init() method is called twice when I refresh the page?


Solution

  • You may want to add additional informations, e.g. JSF Version. Do you have a JSF @ManagedBean or something else like CDI @named bean. In the latter case, you might run into trouble using different cdi-frameworks, see for instance this