Question

I am trying to learn jsf and the thing I read is that it is a stateful web framework. But if i didnt use jsf and just use servlets, I can achieve this statefulness using session scope. So what is meant by a steful web framework? That requet scope and session scope are both the same (stateful)?

Était-ce utile?

La solution

That requet scope and session scope are both the same (stateful)?

This is wrong. @RequestScoped and @SessionScoped are neither the same, nor both stateful.

A @RequestScoped bean is stateless. Nothing is stored here for more than the duration of 1 request. There is a pool of @RequestScoped beans and they can be re-used and be shared among different users. This is only possible if the request itself contains all necessary information.

A @SessionScoped bean is stateful. It is associated with a certain user (Session) and cannot be shared. It will be stored for several requests and can keep a state (thus stateful).

There are many different definitions of what "stateful" and "stateless" are, but you might take the properties of the two scopes as an example of something stateless and something statefull.

But even when using only @RequestScoped beans, your JSF application might not be completely stateless because of how JSF works internally. The new JSF 2.2 goes one more step towards being stateless though. See this explanation for more details of how to go completely stateless with JSF.

But keep in mind that in many cases being stateful (or not stateless) is no problem and not all stateless applications are by definition better than stateful ones.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top