会话范围内的JSF bean中的请求范围内的属性 [英] request scoped property in session scoped JSF bean
本文介绍了会话范围内的JSF bean中的请求范围内的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想让一个会话范围内的JSF bean具有一个请求(页面)范围内的属性.可能吗?
I would like to have a session scoped JSF bean with one property that is request (page) scoped. Is it possible at all?
推荐答案
否,这是不可能的.只能在创建bean的过程中进行托管属性注入.但是,在创建会话范围的bean时,不一定存在请求,并且注入的请求范围的bean在会话的剩余部分中的后续请求中将无效.
No, that's not possible. Managed property injection only happens during creation of the bean. However, when a session scoped bean is been created there is not necessarily a request present and the injected request scoped bean would be invalid in subsequent requests in the remnant of the session.
反之亦然.例如
@ManagedBean
@SessionScoped
public class UserManager {
private User current;
// ...
}
和
@ManagedBean
@RequestScoped
public class Login {
private String username;
private String password;
@ManagedProperty(value="#{userManager}")
private UserManager userManager;
@EJB
private UserService userService;
public String submit() {
User user = userService.find(username, password);
if (user != null) {
userManager.setCurrent(user);
return "home?faces-redirect=true";
} else {
addErrorMessage("Unknown login, please try again");
return null;
}
}
// ...
}
这篇关于会话范围内的JSF bean中的请求范围内的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文