Note: Time-out and eviction of conversations by the container when not in use for a long time to save resoruces is NOT considered in the code below.
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
import java.util.ArrayList;
import java.util.List;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
@NamedInject conversation and the above session scoped bean and invoke
@SessionScoped
public class SRackWorkSpace implements Serializable{
private List<String> cids=new ArrayList<String>();
public void addConversation(String cid){
cids.add(cid);
}
public void removeConversation(String cid){
cids.remove(cid);
}
public boolean isConversationActive(String cid){
return cids.contains(cid);
}
}
- addConversation method when you begin a conversation like
conversation.begin("deliverexam");
sRackWorkSpace.addConversation("deliverexam");
sRackWorkSpace.addConversation("deliverexam");
- removeConversation when we end a conversation like
sRackWorkSpace.removeConversation(conversation.getId());
conversation.end();.
conversation.end();.
You can check of a long running conversation for a desired use case is already active like
if (sRackWorkSpace.isConversationActive("deliverexam")) {
return "/YOUR_PATH_TO_XHTML_VIEW?cid=deliverexam&faces-redirect=true";
}