gpt4 book ai didi

JSF2 无法从 ViewScoped 作为 ManagedProperty 访问 SessionScoped bean

转载 作者:行者123 更新时间:2023-12-02 03:23:53 25 4
gpt4 key购买 nike

我有一个奇怪的问题。 Afaik 我可以将 SessionScoped bean 注入(inject)到 viewscoped 中,因为它比另一个更广泛。这是我的代码:

@ManagedBean
@ViewScoped
public class ProjectBean implements Serializable {

@ManagedProperty(value="#{projectCurrentBean}")
private ProjectCurrentBean currentBean;

public void setCurrentBean(ProjectCurrentBean currentBean) {
this.currentBean = currentBean;
}

@ManagedProperty(value="#{userCredentialsBean}")
private UserCredentialsBean activeUser;

public void setActiveUser(UserCredentialsBean activeUser) {
this.activeUser = activeUser;
}

2个托管bean:

@ManagedBean
@SessionScoped
public class ProjectCurrentBean implements Serializable {

@ManagedBean
@SessionScoped
public class UserCredentialsBean implements Serializable {

它与 UserCredentialsBean 一起工作正常,但是当我放置 ProjectCurrentBean 时它失败了:

Unable to create managed bean projectBean. The following problems were found: - The scope of the object referenced by expression #{projectCurrentBean}, request, is shorter   than the referring managed beans (projectBean) scope of view
为什么? :)

最佳答案

您尚未使用 javax.faces.bean package 中的 @SessionScoped 声明该 bean ,而是来自 javax.enterprise.context package 。这不能与 javax.faces.bean 包中的 @ManagedBean 结合使用。然后,该 bean 将默认为请求范围,其行为类似于 @RequestScoped .

修复您的导入。

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class ProjectCurrentBean implements Serializable {

关于JSF2 无法从 ViewScoped 作为 ManagedProperty 访问 SessionScoped bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8194748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com