【发布时间】:2011-08-22 12:53:01
【问题描述】:
当我第一次访问我的页面时,页面使用的托管 bean 被实例化了两次(我在构造函数中通过了两次,具有相同的堆栈跟踪):
Daemon Thread [http-127.0.0.1-8080-1] (Suspended (breakpoint at line 76 in MyController))
MyController.<init>() line: 76
NativeConstructorAccessorImpl.newInstance0(Constructor, Object[]) line: not available [native method]
NativeConstructorAccessorImpl.newInstance(Object[]) line: 39
DelegatingConstructorAccessorImpl.newInstance(Object[]) line: 27
Constructor<T>.newInstance(Object...) line: 513
Class<T>.newInstance0() line: 355
Class<T>.newInstance() line: 308
ManagedBeanBuilder(BeanBuilder).newBeanInstance() line: 186
...
pass throught two Filters (one of the filter uses Waffle and the other calls a web service...)
...
Http11Protocol$Http11ConnectionHandler.process(Socket) line: 601
JIoEndpoint$Worker.run() line: 447
Thread.run() line: 662
在 xhtml 中:
<a4j:keepAlive beanName="myController"></a4j:keepAlive>
<h:form>
...
</h:form>
在 faces-config.xml 中:
<managed-bean>
<managed-bean-name>myController</managed-bean-name>
<managed-bean-class>com.xx.MyController</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
为什么托管 bean 实例化两次?
感谢您的想法...
使用
- jsf 1.2
- richfaces 3.3.2.SR1
编辑: 感谢Joeri Hendrickx,我发现我有两个不同的请求。所以新的问题是“为什么我在访问我的页面时有两个请求?”
【问题讨论】:
-
由于您的 bean 是请求范围的,因此不应如此。你说你有两次相同的堆栈跟踪;检查Request对象是否相同。
-
你说得对,其实不是同一个请求。说明:在此过程中,我通过了两个过滤器(一个过滤器使用 Waffle,另一个调用 Web 服务...)。
-
@Joeri:你应该重新发布它作为答案,它实际上是两个物理上不同的请求。
-
@BalusC 当然,但我现在问我“为什么我访问我的页面时有两个请求?”。问题刚刚改变。
-
这不是 JSF 问题。只需安装一个 HTTP 流量调试器,如 Fiddler2。我猜你是在使用 Eclipse 和 Tomcat 或 JBoss 并且在服务器完成启动之前触发了第一个请求?
标签: jsf managed-bean ajax4jsf