jsfmanaged-beanajax4jsf

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) :

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 :

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

In the 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 ?

Thank you for your ideas...

Using

Edit: Thanks to Joeri Hendrickx, I found out that I have two differents request. So the new question is "why have I two requests when I access to my page?"


Solution

  • If you get two instances of a request-scoped bean, that should mean you have two requests.

    Check if your browser is sending out two requests (use firebug or 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).