【发布时间】:2015-01-22 07:48:58
【问题描述】:
想象一下这种情况:
我有一个 SessionScoped bean(名为 TheSessionBean),它是另一个 bean(名为 AnotherBean)的 ManagedProperty。
@ManagedBean
@ViewScoped
public class AnotherBean implements Serializable {
@PostConstruct
public void init() {
//Evaluate here!
}
@ManagedProperty(value = "#{theSessionBean}")
private TheSessionBean theSessionBean;
//Getter and Setter...
}
我需要评估 ManagedProperty (theSessionBean) 的值以了解是否可以在没有用户交互的情况下在页面显示之前显示页面。
据我了解,这必须在 PostConstruct 方法中进行评估(这样我才能获得 ManagedProperty 的 Session 的值)。
TheSessionBean 只有一个名为权限的字符串属性。
所以首先我需要知道:
-
theSessionBean.getPermission() == null以重定向到名为one的页面 -
theSessionBean.getPermission().equals("two")以重定向到名为two的页面 More evaluations...
问题是PostConstruct方法必须是void,我需要重定向到对应的页面。
我该怎么做?
【问题讨论】:
-
无论您使用哪种技术(是 Spring 还是完整的 JEE),使用内置安全性不是更好吗?否则,设置一个可用于选择如何显示页面的布尔属性就足够了吗?使用
FacesContext在@PostConstruct中进行程序化重定向对我来说没有任何意义,如果可能的话。