0

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.

6
  • 1
    I'm not familiar with the @Controller annotation being one from JSF. And @Viewscoped is not for usage per tab. It is for scope per viewId, effectively resulting in the behaviour you see. You need a @WindowScoped from DeltaSpike or use a @ConversationScoped. There is a duplicate about this in Stackoverflow. Commented Apr 14, 2020 at 12:33
  • @BalusC: no, not using Spring, it's JSF with some additional services provided by a framework I have to use. Commented Apr 14, 2020 at 12:43
  • @Kukeltje: my mistake, I didn't provide the declaration of @Controller. Just did it. Sorry, but we have a bad history with @ConversationScoped, so it is not an option for us, since the medicine was much worse than the decease. Any other ideas? Commented Apr 14, 2020 at 12:48
  • @BalusC: alright, just to be absolutely sure that I understand my case here. You are telling me that in an absolutely standard JSF application I should be able to have one backing bean per browser tab with no problem if I use @ViewScope. Is that so? Commented Apr 14, 2020 at 13:24
  • 1
    Suggestion: WindowScoped... And if the @Controller is in a custom framework, it is impossible to help further (at least for me since lots of things might happen in there) Commented Apr 14, 2020 at 15:04

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Digging the internet? Why? I commented two weeks ago about this scope...! if this works for you it is normally common practice (out ofcourtesy) to ask the one suggesting it to create answer
Sorry, but I just reviewed your comments and found your suggestion, but you posted it after I decided to go further on the matter. It was not my intention to not give you the proper credit, but because the pressure I was suffering I did not have the time to get back here and see it. Please, post an answer and I will accept it as the correct one.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.