JSF 2应用程序中默认的Managed Bean Scope是什么? [英] What is the default Managed Bean Scope in a JSF 2 application?

查看:83
本文介绍了JSF 2应用程序中默认的Managed Bean Scope是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,默认范围是请求"范围.我尝试删除范围注释,并期望bean具有请求bean的行为(通过在上一页上返回已提交的值,我记得我已经尝试过了,并且工作正常),但是我什么都没有与其连接的表达语言. 那么默认范围是什么,为什么它不是相同的行为?!

Normally the default scope is the Request scope. I ve tried to delete the scope annotation and expected the bean to have a request bean scopped behaviour (by returning a submitted value on a previous page, I remember i've tried this the past and it worked fine) but i got nothing on the expression language wired to it. So what is the default scope and why it's not the same behaviour?!

推荐答案

取决于谁在管理bean.

Depends on who's managing the bean.

如果通过JSF > @ManagedBean ,则默认为 @RequestScoped ,如 javadoc中所述:

如果省略了范围注释,则必须像存在RequestScoped注释一样处理Bean

If the scope annotations are omitted, the bean must be handled as if the RequestScoped annotation is present

如果通过 @Named ,则默认为 ,如焊接文档中所述:

最后,CDI具有所谓的依赖伪镜.这是未显式声​​明作用域类型的bean的默认作用域.

Finally, CDI features the so-called dependent pseudo-scope. This is the default scope for a bean which does not explicitly declare a scope type.

效果是在每个单个EL表达式上都新创建了bean实例.因此,想象一个登录表单,其中有两个输入字段引用一个bean属性,一个命令按钮引用一个bean操作,因此总共有三个EL表达式,那么实际上将创建三个实例.一种设置了用户名,一种设置了密码,另一种调用了操作.实际上,它的行为与JSF @NoneScoped .这可以确认您所看到的症状.

The effect is that the bean instance is newly created on every single EL expression. So, imagine a login form with two input fields referring a bean property and a command button referring a bean action, thus with in total three EL expressions, then effectively three instances will be created. One with the username set, one with the password set and one on which the action is invoked. In effects, this behaves the same as JSF @NoneScoped. This confirms the symptoms you're seeing.

如果通过Spring ="noreferrer"> @Component ,则默认为 ,如

If it's Spring via @Component, then it defaults to @Scope("singleton"), as mentioned in javadoc:

默认值:"singleton"

实际上,这与JSF @ApplicationScoped 和CDI @ApplicationScoped .

In effects, this behaves the same as JSF @ApplicationScoped and CDI @ApplicationScoped.

Netbeans与它无关.它只是像记事本这样的编辑工具,但是具有1000多个额外功能.

Netbeans has got nothing to do with it. It's just an editing tool like notepad but then with 1000+ extra features.

  • what is none scope bean and when to use it?
  • How to choose the right bean scope?

这篇关于JSF 2应用程序中默认的Managed Bean Scope是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆