1
votes

While inside a not trasient conversation, I need to start a new conversation for the bean.

The case is the following: I have a jsf page with a cdi bean to handle creation and altering of an order. On the menu of the page there is an item which is "new Order". So, when altering an Order, I need to click on "new Order" and the page must be refreshed with the new CID, and a new conversation scope. But if I try to do this, the conversation.getConverstaionId() always return the same value, even if I call conversation.end() and conversation.begin() first.

EDIT:

I have a page to edit an order. When clicking on a new button (of the menu), I want it to refresh and start a new conversation, to add a new order. So this button calls the method redirectToNewOrderPage(). But it has the problem described on the code and before.

@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

1 Answers

1
votes

What you are trying to do, does not work. The conversation scope in CDI is not as power as the one from Seam 2 (if that's where you're coming from).