我在MyPage.java
中遇到以下情况:
import org.apache.tapestry5.Link;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.hibernate.annotations.CommitAfter;
public MyPage {
@Property
@Persist
private SubmitAction submitAction; // an enumeration
@OnEvent(value = EventConstants.SUCCESS, component = "mainForm")
Object onSuccessFromMainForm() {
Link link = null;
commitSomething();
if (submitAction != null && this.submitAction.equals(SubmitAction.APPROVE)) {
link = linkService.getLink(AnotherPage.class, true, "anotherPage");
} else {
link = linkService.getLink(MyPage.class, actionId, documentId);
}
return link;
}
@CommitAfter
private void commitSomething() {
// here are some interaction with Dao and Service layers.
}
Object onActivate(Long actionId, Long documentId) {
// url handler
// do something
return null;
}
}
这个想法是,如果满足某些条件可以链接到AnotherPage
:
http://localhost:7001/myproject/anotherpage
否则,使用url参数留在同一页面上:
http://localhost:7001/myproject/mypage/678123/567234
预期的行为是@CommitAfter
在两种情况下均应工作,但仅在链接指向同一页面时才起作用。
您知道为什么会发生这种情况吗?
编辑:
实际上,我找到了一个解决方案-这不仅是Apache Tapestry
的问题。
主要问题是我的业务逻辑取决于onActivate
。 Apache tapestry
无法使用此方法设置一些@Persist
字段并破坏了我的逻辑。我添加了onPassivate
方法,现在可以正常使用了。
如果您失去了时间,我们深表歉意,感谢您的所有回答!
答案 0 :(得分:0)
您只能将@CommitAfter放在挂毯调用的方法上。 Tapestry不知道您的commitSomething()
方法是私有的。它无法拦截此方法调用