request scoped property in session scoped JSF bean

↘锁芯ラ 提交于 2019-11-29 04:12:38

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.

Do it the other way round. E.g.

@ManagedBean
@SessionScoped
public class UserManager {

    private User current;

    // ...
}

and

@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;
        }
    }

    // ...
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!