spring-bootjsfcdimanaged-beanview-scope

@ViewScoped bean behaves like @SessionScoped or @ApplicationScoped


I have a Spring Boot application using JSF/CDI. Backing beans are annotated with @Named @ViewScoped, but while browsing between other pages values still stay on textboxes. Values should've been cleared. In other words, the backing beans unexpectedly behave like @SessionScoped or @ApplicationScoped.

My input

<p:inputText value="#{parameterBean.spreadValue}" label=" "
                                styleClass="inputText" id="spreadValue">
                                <p:ajax event="change" />
                                <p:ajax event="valueChange" />
</p:inputText>

My bean

@Named("parameterBean")
@ViewScoped
public class parameterBean implements Serializable {
    // ...
}

This is JSF configuration

@Configuration
public class JSFConfig {

    @Bean
    ServletRegistrationBean<FacesServlet> jsfServletRegistration(ServletContext servletContext) {
        servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString());
        // FacesServlet registration
        ServletRegistrationBean<FacesServlet> srb = new ServletRegistrationBean<>();
        srb.setServlet(new FacesServlet());
        srb.setUrlMappings(Arrays.asList("*.xhtml"));
        srb.setLoadOnStartup(1);
        return srb;
    }

}

Solution

  • ViewScoped doesn't work for Spring Boot and JSF. Had to implement custom ViewScope using BeanFactoryPostProcessor Interface.