JSF 会话 ManagedBean 在每个请求时实例化
我的应用程序中有一个 @ManagedBean,带有 @sessionScoped 注释。
问题是,每个请求都会调用公共无参数构造函数,因此我的字段被重置,并且我的模型逻辑进入空间。
我尝试构建和清理,重置 glassFish,但仍然在每个请求时调用 bean 构造函数。 我还有一个 faces-config.xml 来控制页面导航。
我可以通过在 faces-config 中重新声明 bean 来解决这个问题,现在它可以工作了......
你知道为什么会发生这种情况吗?如果我删除 faces-config,问题仍然存在。
谢谢大家!
I have a @ManagedBean in my app, with the @sessionScoped anotation.
The problem is that the public no arg constructor is being called for each request, so my fields are being reseted and my model logic goes to space.
I tried build and clean, reset glassFish, but still the bean constructor get's called at each request.
I also have a faces-config.xml to control the page navigation.
I could solve this by redeclaring the bean inside the faces-config, now it work's...
Any ideas of why that's happening? If i delete the faces-config, the problem persists.
Thanks everybody!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
@SessionScoped
不属于javax.faces.bean
包,但不是完全不同的 API,例如javax.enterprise.context
包。仔细检查您的导入并小心 IDE 自动完成。 IDE 倾向于按包名称对自动建议进行排序,因此 javax.enterprise.context 将显示为第一个选项。如果您没有在
@ManagedBean
上使用任何javax.faces.bean
范围注释,则该 bean 将默认为@NoneScoped
,这意味着它是在每个单独的#{bean}
EL 评估。另请参阅:
That can happen if
@SessionScoped
is not of thejavax.faces.bean
package, but instead of a completely different API, for example thejavax.enterprise.context
package. Doublecheck your imports and be careful with IDE autocompletion. IDEs tend to sort autosuggestions by package name and thus thejavax.enterprise.context
would appear as 1st option.If you aren't using any
javax.faces.bean
scope annotation on a@ManagedBean
, then the bean will default to@NoneScoped
, which means that it's constructed on every single#{bean}
EL evaluation.See also: