【发布时间】:2012-03-23 06:22:20
【问题描述】:
在一个不短暂的对话中,我需要为 bean 开始一个新的对话。
案例如下:我有一个带有 cdi bean 的 jsf 页面来处理订单的创建和更改。在页面的菜单上有一个项目是“新订单”。因此,在更改订单时,我需要单击“新订单”,并且必须使用新的 CID 和新的对话范围刷新页面。但是如果我尝试这样做,即使我先调用了 conversation.end() 和 conversation.begin(),conversation.getConverstaionId() 总是返回相同的值。
编辑:
我有一个页面可以编辑订单。单击(菜单的)新按钮时,我希望它刷新并开始新对话,以添加新订单。所以这个按钮调用了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;
}
}
【问题讨论】:
标签: jsf jakarta-ee cdi