1

I am new to Spring/JSF.

I have a controller which is annotated by @Component which have a @Autowired class UserClass which has,

@Scope(value=org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE)

I need to create a new UserClass instance for each new request so my controller is annotated with @Scope("request") which works perfectly(Creating new instance for each request) with this annotation.

But it broke the ajax calls in <p:dataTable> selection, commondLink, <f:setPropertyActionListener...

NOTE : if I change the @Scope("request") to @ViewScoped the ajax works but my UserClass becomes singleton and all the data is shared between the threads.

I googled and got to know we need to either use JSF annotations or Spring but here I am using only Spring annotations.

And I found this, PrimeFaces doesn't work when bean scope is request but couldn't understand.

Tiny
  • 27,221
  • 105
  • 339
  • 599
Gopi Lal
  • 417
  • 5
  • 23

1 Answers1

1

A component library like Primefaces heavily relies in a stateful model, which means using at least the view scope in your managed beans. If you use the request scope you'll be recreating the managed bean for every single request, including ajax requests, which I guess it isn't what you want (not the way to go with JSF, at least).

Your best is to use a custom Spring Scope in order to emulate the JSF view scope. I like this approach from the PF team (a bit old post, but still you can tune it for newer Spring versions) or this one, which is more elaborated.

Aritz
  • 30,971
  • 16
  • 136
  • 217