seam框架中的conversation是个非常的棒的东西,但是在页面开启长对话后,结束的方法比较困惑,使用@End注解终觉得不踏实。我现在尝试的事件驱动模型解决方案如下。
在导航文件中如下配置:

<page view-id="/test/*" login-required="true"></page>
<page view-id="/test/listDepartment.xhtml">
<action execute="#{org.jboss.seam.core.events.instance().raiseEvent('pageScopeControl', 'department')}"/>
<navigation from-action="#{departmentBean.add}">
<redirect view-id="/test/editDepartment.xhtml" />
</navigation>
</page>


然后建立一个Observer组件:

@Name("pageScopeObserver")
@Scope(ScopeType.SESSION)
public class PageScopeObserver {
private String curPageScope;
private String prePageScope;


@In(value = "org.jboss.seam.core.conversation",required = false)
Conversation conversation;

@Observer("pageScopeControl")
synchronized public void fetchPageScopeEvent(String pageEvent) {
curPageScope = pageEvent;
if (curPageScope.equals(prePageScope) == false) {
prePageScope = curPageScope;
if (conversation != null) {
conversation.end();
conversation.leave();
}
}
}

这样可以实现通过定制各种不同的事件类型,将单个页面或一组页面的conversation管理起来。
希望大家提点意见。

更多推荐

Seam页面conversation作用域的控制问题