AlexSC
AlexSC

Reputation: 1943

How to have one instance of Backing Bean per Browser tab?

My environment: Java 7/JSF 2.1/PrimeFaces 6.1.

My goal: to have a certain page of my application instantiated many times, one for each browser tab, each one with a different context.

My problem: everytime I open a second browser tab requesting from the same url, but with different object id, the previous one is destroyed, so only one backing bean instance is kept alive.

How do I know that: In my backing bean I have one method annotated with @PosConstruct and other with @PreDestroy, so I can track the life cicle of the instances.

My backing bean is annotated as follows:

@ViewController
public class MyBackingBeanMB extends AbstractBackingBeanMB {
    private static final long serialVersionUID = 1L;

    // many fields and methods
}

The @ViewController annotation is provided by the application framework I have to use. Such an annotation is declared as:

@Named
@Controller
@Stereotype
@ViewScoped // For me, this should do the trick, but...
@Target(value={TYPE})
@Retention(value=RUNTIME)
@Inherited
public @interface ViewController {
}

Update 1:

The @Controller annotation is also provided by the framework I use and is declared as:

@InterceptorBinding
@Inherited
@Target({ TYPE, METHOD })
@Retention(RUNTIME)
public @interface Controller {
}

Any ideas of what could be wrong?

TIA.

Upvotes: 0

Views: 277

Answers (1)

AlexSC
AlexSC

Reputation: 1943

After some digging in the Internet I found Apache DeltaSpike, which provider a new kind of managed bean scope, WindowScoped.

Managed beans annotated with @WindowScoped` operate just like I wanted, providing me with the exact behaviour I needed and it is absolutely compatible with the framework I have to use.

Upvotes: 1

Related Questions