无效会话,然后重定向重新创建Bean

时间:2020-08-06 05:40:12

标签: jsf jsf-2.2 managed-bean session-scope

使用@SessionScoped bean中定义的JSF验证器方法:

public void doValidation(FacesContext context, UIComponent component, Object value) throws ValidatorException {
    // throws ValidatorException on invalid input
    ...
    // But, in some cases we want to lock out the user by invalidating session and redirecting to a different error page
    ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
    ec.invalidateSession();
    ec.redirect(errorPage);
}

但是,我在重定向上看到的行为是,而不是/在转到错误页面之前,@ SessionScoped bean似乎正在重新创建(正在调用其构造函数和@PostConstruct)。 删除invalidateSession()调用后,它将直接转到errorPage,而无需重新创建bean。请注意,错误页面没有对此bean的引用。

0 个答案:

没有答案
相关问题