@PostConstruct called multiple time for @ConversationScoped bean

I have a @ConversationScoped bean using the start method, for example:

@PostConstruct
public void start() {
    if (conversation.isTransient()) {
        conversation.begin();
        log.debug("conversation.getId(): " + conversation.getId());
    }
}

My problem is that every time the page is refreshed, a new conversation starts, a new conversation also starts every time I have an AJAX call to a method in a bean (which is my main problem).

What I really want to do is that the chat chat hangs until I manually call chat.end (). What am I missing here?

+3
source share
6 answers

Have you verified that calls (AJAX) include a conversation identifier (cid) parameter?

If this is absent, it is expected that a new conversation will begin for each call.

+3
source

, , , :

100%, @PostConstruct - . face-event :

<f:metadata>
        <f:event type="javax.faces.event.PreRenderViewEvent"
                listener="#{myBean.init}" />
</f:metadata>

, , JSF-postback.

public void init() {
       if (!FacesContext.getCurrentInstance().isPostback() && conversation.isTransient()) {
          conversation.begin();
       }
    }

Seam 3, :

<f:metadata>
   <s:viewAction action="#{myBean.init}" if="#{conversation.transient}" />
</f:metadata>
+5

JSR-299 . , JSF. @PreRenderViewEvent , @ConversationScoped bean longRunning.

Apache MyFaces CODI @ConversationScoped. CODI - CDI, , , Apache OpenWebBeans, Weld. , @ViewScoped, @ViewAccessScoped ( ) @WindowScoped.

: https://cwiki.apache.org/confluence/display/EXTCDI/Index

+3

:

:

JSF .

, . JSF . :

JSF .   , JSF, .

: .

   , Conversation.begin()    , Conversation.end()

, , .

, JSF, JSF, .

, JSF, JSF, . :

, , JSF, ( JSF), .    , , JSF ( JSF NavigationHandler), URL. GET cid, .    , , GET cid, . .

JSF, . HTTP . :

HTTP , , , servlet service().    , JSF, .

:    ,

+2

CDI- , struberg . , CDI + CODI 1, . @ConversationScoped . @ViewAccessScoped. , struberg , !

0

, Facelet, , "cid", AJAX , "cid" .

<f:metadata>
    <f:event listener="#{myBean.dummy}" type="preRenderView" />
</f:metadata>

MyBean.java

public void dummy() {}
0

All Articles