重定向到另一个页面后,Apache Tapestry @CommitAfter不起作用

时间:2019-01-23 09:20:58

标签: java tapestry

我在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;
    }
}

这个想法是,如果满足某些条件可以链接到AnotherPagehttp://localhost:7001/myproject/anotherpage

否则,使用url参数留在同一页面上: http://localhost:7001/myproject/mypage/678123/567234

预期的行为是@CommitAfter在两种情况下均应工作,但仅在链接指向同一页面时才起作用。

您知道为什么会发生这种情况吗?


编辑:

实际上,我找到了一个解决方案-这不仅是Apache Tapestry的问题。 主要问题是我的业务逻辑取决于onActivateApache tapestry无法使用此方法设置一些@Persist字段并破坏了我的逻辑。我添加了onPassivate方法,现在可以正常使用了。

如果您失去了时间,我们深表歉意,感谢您的所有回答!

1 个答案:

答案 0 :(得分:0)

您只能将@CommitAfter放在挂毯调用的方法上。 Tapestry不知道您的commitSomething()方法是私有的。它无法拦截此方法调用

相关问题