1

我已将用户名和密码绑定到后备托管 bean。在后台 bean 中,当我使用 DB 检查用户名和密码时,我想将页面从 重定向login.xhtmlhome.xhtml. 我怎样才能做到这一点?

4

1 回答 1

6

只需返回附加faces-redirect=true参数的视图 ID。

例如

public String login() {
    User found = userService.find(username, password);

    if (found != null) {
        this.user = found;
        return "home?faces-redirect=true"; // Will redirect to home.xhtml.
    }
    else {
        addGlobalErrorMessage("Unknown login, please try again");
        return null; // Will stay in current view (and show error message).
    }
}
于 2012-05-20T12:16:34.147 回答