Wicket:没有调用Ajax回调onTimer()方法

时间:2012-07-28 09:28:16

标签: ajax wicket

我使用wicket 1.5来开发web应用程序。我有三个网页,主页,父网页和面板。当我在ParentWebpage中设置一个AbstractAjaxTimerBehavior并在回调函数onTimer()中调用Panel时,每件事都没有问题。但是在面板中也是一个AbstractAjaxTimerBehavior并且从不调用onTimer的回调函数,但为什么??

这是我的例子:

HomePage.java

BookmarkablePageLink bookmarkablePageLink = new BookmarkablePageLink("linkToCurrentDiagnosePage", TestParent.class);
bookmarkablePageLink.add("label");
item.add(bookmarkablePageLink);

- >现在我可以导航到TestParent类

TestParent.java

public class TestParent extends WebPage {
    /** The Constant logger. */
    private static final Logger LOGGER = Logger.getLogger(TestParent.class);
    boolean isSet = false;
    public TestParent() {
        LOGGER.error("Parent -> Cstr");
        Fragment fragment = new Fragment("fragments", "fragment1", TestParent.this);
        fragment.setOutputMarkupId(true);
        add(fragment);

        add(new AbstractAjaxTimerBehavior(Duration.seconds(1)) {

            @Override
            protected void onTimer(AjaxRequestTarget target) {
                LOGGER.error("Parent -> I'am here");
                if(isSet == false){
                    LOGGER.error("Parent -> I set the panel");
                    isSet = true;
                    Fragment fragment = new Fragment("fragments", "fragment2", TestParent.this);
                    fragment.setOutputMarkupId(true);
                    fragment.add(new TestChild("panel"));
                    TestParent.this.replace(fragment);
                    target.add(fragment);
                }
            }
        });
    }
}

TestParent.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <span wicket:id="fragments"></span>

    <wicket:fragment wicket:id="fragment1">
        FILL TEXT
    </wicket:fragment>

    <wicket:fragment wicket:id="fragment2">
        <span wicket:id="panel">[message]</span>
    </wicket:fragment>
</body>
</html>

TestChild.java

public class TestChild extends Panel {
    private static final Logger LOGGER = Logger.getLogger(TestChild.class);

    public TestChild(String id) {
        super(id);
        LOGGER.error("Child -> Cstr");

        add(new AbstractAjaxTimerBehavior(Duration.seconds(1)) {

            @Override
            protected void onTimer(AjaxRequestTarget target) {
                LOGGER.error("CHILD --> I'am here");
            }
        });               
    }
}

TestChild.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <wicket:panel>

    </wicket:panel>
</body>

输出:

ERROR - TestParent                 - Parent -> Cstr

ERROR - TestParent                 - Parent -> I'am here

ERROR - TestParent                 - Parent -> I set the panel

ERROR - TestChild                  - Child -> Cstr

ERROR - TestParent                 - Parent -> I'am here

ERROR - TestParent                 - Parent -> I'am here

ERROR - TestParent                 - Parent -> I'am here

ERROR - TestParent                 - Parent -> I'am here

1 个答案:

答案 0 :(得分:0)

假设您使用的是真实代码,这是因为您使用1秒计时器创建它们。然后在您的计时器代码中重新创建子面板(因此还有子计时器行为)。儿童小组永远不会有机会开火!