我使用 wicket 1.5 开发 web 应用程序。我有三个网页,主页、ParentWebpage 和一个面板。当我在 ParentWebpage 中设置 AbstractAjaxTimerBehavior 并在面板中调用回调函数 onTimer() 时,一切都很好。但是面板中也是 AbstractAjaxTimerBehavior 并且从不调用回调函数 onTimer,但是为什么?
这是我的例子:
主页.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