views:

29

answers:

2

I've noticed that when using Ajax heavy JSF 1.2 implementations like Richfaces you're somehow forced to declare more managed beans than you'll want as Session scoped so that state can be maintained across multiple Ajax requests; there are components that will just stop working.

For instance, I developed this application lately in which I had to declare almost all my JSF Backing Beans as Session Scoped in order to have component "x" working. Is there a way out of this, do you consider it a bad practice, or is just the price to pay for having Ajax enabled component in JSF 1.2.

Thanks in advanced.

+2  A: 

Session scope beans increase memory usage.

Another available scope is View Scope - This allows to keep a state of a bean between requests, while the user is still on the same view.

If you are using JSF2, please consider using @ViewScope above the bean name:

    @ViewScope
    public class myBean{
     ..
     }

If you use RichFaces and JSF1.2, consider using <a4j:keepAlive /> under <f:view> in the view. for example:

<a4j:keepAlive beanName = "#{myBean}"/>

Read more info here

Odelya
+1, just have in mind the bean has to be serializable
Bozho
A: 

Another option is to use Seam conversation. Also, I wouldn't say components stop working, they still work.. it's your logic that needs to maintain some sort of state on the server.

Max Katz