问题描述
我的环境:Java 7/JSF 2.1/PrimeFaces 6.1.
我的目标:要实例化应用程序的某个页面多次,每个浏览器选项卡一个,每个页面具有不同的上下文.
我的问题:每次我打开第二个浏览器选项卡时,从相同的URL请求但对象ID不同,前一个被销毁,因此只有一个后备bean实例保持活动状态. >
我怎么知道:在我的后备豆中,有一种方法用@PosConstruct
注释,另一种方法用@PreDestroy
注释,因此我可以跟踪实例的生命周期.
我的后备豆的注释如下:
@ViewController
public class MyBackingBeanMB extends AbstractBackingBeanMB {
private static final long serialVersionUID = 1L;
// many fields and methods
}
@ViewController
批注由我必须使用的应用程序框架提供.这样的注释声明为:
@Named
@Controller
@Stereotype
@ViewScoped // For me, this should do the trick, but...
@Target(value={TYPE})
@Retention(value=RUNTIME)
@Inherited
public @interface ViewController {
}
更新1:
@Controller
注释也由我使用的框架提供,并声明为:
@InterceptorBinding
@Inherited
@Target({ TYPE, METHOD })
@Retention(RUNTIME)
public @interface Controller {
}
有什么问题的想法吗?
TIA.
在Internet上进行一些挖掘之后,我找到了Apache DeltaSpike,它提供了一种新型的托管bean作用域WindowScoped
.
带有@ WindowScoped`注释的托管bean的运行方式与我想要的一样,为我提供了所需的确切行为,并且与我必须使用的框架完全兼容.
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.
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.
这篇关于每个“浏览器"选项卡上如何有一个Backing Bean实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!