[英]Request scoped attributes in session scoped bean JSF
The application that I'm working on uses a huge legacy bean that is session scoped. 我正在处理的应用程序使用了一个会话范围内的巨大遗留bean。 The problem is I can't refactor the code and I need some attributes to be request scoped.
问题是我无法重构代码,并且我需要一些属性以请求范围。 Is there any way to achieve that?
有什么办法可以实现?
You could have a @RequestScoped
bean, inject the legacy session scoped bean by using @ManagedProperty
and use @PostConstruct
to retrieve the attributes you need. 您可以有一个
@RequestScoped
bean,使用@ManagedProperty
注入旧的会话范围的bean,并使用@PostConstruct
检索所需的属性。
For example: 例如:
@ManagedBean(name = "legacyBean")
@SessionScoped
public class LegacyBean implements Serializable {
private Object attr1;
private Object attr2;
// Getters and setters
}
@ManagedBean(name = "requestScopedBean")
@RequestScoped
public class RequestScopedBean {
private Object requestAttr1;
@ManagedProperty(value = "#{legacyBean}")
private LegacyBean legacyBean;
@PostConstruct
private void init() {
this.requestAttr1 = legacyBean.getAttr1();
}
public Object getRequestAttr1() {
return this.requestAttr1 ;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.