문제

I'm using the CDI conversation scope and it's ok when user follows the normal scenario. However, when user don't complete de "conversation" I get this error:

WELD-000214 Attempt to call begin() on a long-running conversation

Obviously, is because there are 2 calls to the begin method without calling the end method.

To clarify it this is my scenario:

  • In the first page the user search for a product by a reference number. If it's found I call the conversation.begin and navigate to the product details page.
  • In this page when the user push save button and in this point I call the conversation.end.

The problem is when being in the details page the user leaves out (for instance, clicking an link in the menu), so the end method is not called. And when their return to the search page I get the error because begin is called again.

I think, one possible solution may be to call the end method when user exists the second page. But I don't know how to achieve this.

(I'm using JSF 2.1, and Weld 1.1.6 implementation of CDI)

Thanks in advance

도움이 되었습니까?

해결책

This behaviour is intentional. You can easily check conversation.isTransient() to decide whether you want to / need to make a conversation long-running.

If begin() is called, and the current conversation is already marked long-running, an IllegalStateException is thrown.

(see the spec here)

다른 팁

Always begin conversation checking first is conversation ended using isTransient() method.

public void beginConversation(){
    if (!conversation.isTransient()){
        conversation.end();
    }
    conversation.begin();
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top