2012-04-24 42 views
1

我正在使用CDI對話範圍,並且在用戶遵循正常場景時沒有問題。但是,當用戶沒有完成去「談話」我得到這個錯誤:當開始被調用兩次時,JSF/CDI對話範圍中的錯誤

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

顯然,是因爲有2個呼叫到開始方法,無需調用年底方法。

要澄清,這是我的情景:

  • 在第一頁中,用戶在搜索產品由參考 數。如果發現我打電話給對話。開頭並導航到 產品詳細信息頁面。
  • 在這個頁面,當用戶按壓保存按鈕 在這一點上,我叫conversation.end

的問題是在明細頁面,用戶離開了是時候(例如,點擊菜單中的鏈接),所以年底方法不叫。當他們返回到搜索頁面時,我得到錯誤,因爲開始被再次調用。

我認爲,當用戶存在第二個頁面時,一種可能的解決方案可能是調用結束方法。但我不知道如何實現這一點。

(我使用的是JSF 2.1,和焊接1.1.6執行CDI)的提前

回答

3

由於此行爲是故意的。您可以輕鬆檢查conversation.isTransient()以決定是否要/需要長時間進行對話。

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

see the spec here

1

始終開始談話第一檢查是使用isTransient()方法談話結束。

public void beginConversation(){ 
    if (!conversation.isTransient()){ 
     conversation.end(); 
    } 
    conversation.begin(); 
} 
相關問題