简体   繁体   English

托管Bean的两个实例化

[英]Two instantiations of the managed-bean

When I access to my page for the fist time, the managed bean used by the page is instantiate two times (I pass two times in the contructor, with the same stack trace) : 当我第一次访问我的页面时,该页面使用的托管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  

In the xhtml : 在xhtml中:

<a4j:keepAlive beanName="myController"></a4j:keepAlive>
<h:form>
...
</h:form>

In the faces-config.xml : 在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>

Why does the managed bean is instanciate two times ? 为什么托管bean实例化两次?

Thank you for your ideas... 谢谢你的想法...

Using 运用

  • jsf 1.2 jsf 1.2
  • richfaces 3.3.2.SR1 richfaces 3.3.2.SR1

Edit: Thanks to Joeri Hendrickx, I found out that I have two differents request. 编辑:感谢Joeri Hendrickx,我发现我有两个不同的要求。 So the new question is "why have I two requests when I access to my page?" 因此,新问题是“为什么访问页面时我有两个请求?”

If you get two instances of a request-scoped bean, that should mean you have two requests. 如果有两个请求范围的Bean实例,则意味着您有两个请求。

Check if your browser is sending out two requests (use firebug or fiddler). 检查您的浏览器是否正在发送两个请求(使用Firebug或Fiddler)。 If it's sending out only one, that means your request is duplicated somewhere in the stack (porbably in a filter, or maybe even in a custom servlet). 如果只发送一个,则意味着您的请求在堆栈中的某个位置重复(可能在过滤器中,甚至在自定义servlet中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM