新的CDI对话

时间:2012-03-05 19:07:58

标签: jsf java-ee cdi

在非交易对话中,我需要为bean开始新的对话。

案例如下:我有一个带有cdi bean的jsf页面来处理订单的创建和更改。在页面的菜单上有一个项目是“新订单”。因此,在更改订单时,我需要单击“新订单”,并且必须使用新的CID和新的会话范围刷新页面。但是如果我尝试这样做,session.getConverstaionId()总是返回相同的值,即使我先调用conversation.end()和conversation.begin()。

编辑:

我有一个页面来编辑订单。当点击菜单上的新按钮时,我希望它刷新并开始新的对话,以添加新订单。所以这个按钮调用方法redirectToNewOrderPage()。但它有代码中描述的问题以及之前的问题。

@Named
@ConversationScoped
public class OrderEditBean implements Serializable {
    private static final long serialVersionUID = 1L;

    @Inject
    private Conversation conversation;

    [...]


    public void redirectToNewOrderPage() {
        String cid = createNewConversationId();
        setOrder(null);
        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect("/OrdersManager/restricted/orders/edit.xhtml?cid=" + cid);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private String createNewConversationId() {
        String oldConversationId = null;
        String newConversationId = null;
        oldConversationId = conversation.getId();

        if (!conversation.isTransient() && conversation.getId() != null) {
            conversation.end();
        }

        conversation.begin();
        newConversationId = conversation.getId();

        // **************
        // at this point newConversationId is equal to 
        // oldConversationId if the conversation was NOT transient.
        // **************

        return newConversationId;
    }

}

1 个答案:

答案 0 :(得分:1)

你想做什么,不行。 CDI中的对话范围不如Seam 2中的对话范围(如果那是你来自的地方)。

相关问题