我正在将应用程序从较旧版本的wicket迁移到wicket 8.有些页面工作正常(简单页面,如登录)。这些页面不使用扩展机制。 当我访问具有该机制的页面时,它不起作用。我不知道这是不是一个错误,但我尝试了一切,无法找到解决方案。 我正在使用wicket 8.0.0-M5 (我的kwnow不是一个稳定版本)。有人有同样的问题吗? 这是我的代码:
WerklijstPageXXX.html
<html xmlns:wicket>
<body>
<wicket:extend>
<div wicket:id="panelXXX"></div>
</wicket:extend>
</body>
WerklijstPanelXXX.html
<wicket:head xmlns:wicket>
</wicket:head>
<wicket:panel xmlns:wicket>
<div wicket:id="filter">
<div wicket:id="label"></div>
</div>
</wicket:panel>
WerklijstPageXXX.java
public class WerklijstPageXXX extends BasePage {
private WerklijstPanelXXX werklijstPanel;
public WerklijstPageXXX() {
werklijstPanel = new WerklijstPanelXXX("panelXXX"){};
add(werklijstPanel);
}
@Override
public Panel getContextPanel(String id)
{
return werklijstPanel.getWerklijstFilterPanel();
}
WerklijstPanelXXX.java
public abstract class WerklijstPanelXXX extends Panel {
private static final Logger LOG = LoggerFactory
.getLogger(WerklijstPanelXXX.class);
private Panel filterPanel;
public WerklijstPanelXXX(String id) {
super(id);
WebMarkupContainer upperPanel = new WebMarkupContainer("filter");
filterPanel = new Panel("filterPanel") {
};
add(upperPanel);
upperPanel.add(new Label("label"));
}
public Panel getWerklijstFilterPanel() {
return filterPanel;
}
编辑: BasePage.html(部分内容)
<div id="body" class="body">
<div id="aside" class="aside">
<div wicket:id="contextPanel"></div>
</div>
<div id="content" class="content">
<div class="padding">
<wicket:child></wicket:child>
</div>
</div>
</div>
BasePage.java
@Override
protected void onInitialize() {
super.onInitialize();
add(getContextPanel("contextPanel"));
addTabMenu();
addMenu();
addPatientBar();
}
错误:
根本原因:
org.apache.wicket.WicketRuntimeException:下面的组件无法呈现。可能的原因可能是: 1)您在代码中添加了一个组件但忘记在标记中引用它(因此组件永远不会被渲染), 2)如果您的组件已添加到父容器中,请确保子容器的标记包含它们。
[Panel [Component id = filterPanel,page = nl.philips.raris.web.werklijst.WerklijstPageXXX,path = filterPanel,type = org.apache.wicket.markup.html.panel.Panel,isVisible = true,isVersioned = true]]
at org.apache.wicket.Page.checkRendering(Page.java:662) 在org.apache.wicket.Page.onAfterRender(Page.java:805) 在org.apache.wicket.markup.html.WebPage.onAfterRender(WebPage.java:209) 在org.apache.wicket.Component.afterRender(Component.java:919) 在org.apache.wicket.Component.render(Component.java:2335) 在org.apache.wicket.Page.renderPage(Page.java:987) 在org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(WebPageRenderer.java:124) 在org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:236) 在org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:175) at org.apache.wicket.request.cycle.RequestCycle $ HandlerExecutor.respond(RequestCycle.java:912) 在org.apache.wicket.request.RequestHandlerExecutor.execute(RequestHandlerExecutor.java:65) 在org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:283) 在org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:253) at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:221) 在org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:262) 在org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:204) 在org.apache.wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:137) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:687) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:790) 在org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:808) 在org.eclipse.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1669) 在org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) 在org.apache.shiro.web.servlet.AbstractShiroFilter $ 1.call(AbstractShiroFilter.java:365) 在org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) 在org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) 在org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387) 在org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) 在org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) 在org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) 在org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) 在org.eclipse.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1652) 在org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:151) 在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 在org.eclipse.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1652)
答案 0 :(得分:2)
Java和HTML组件树应匹配。
您的HTML状态为:<div wicket:id="*contextPanel*"></div>
,但您的Java代码会返回ID为filterPanel
的Panel。
public WerklijstPageXXX() {
werklijstPanel = new WerklijstPanelXXX("panelXXX"){};
add(werklijstPanel);
}
@Override
public Panel getContextPanel(String id) // HERE id is ignored
{
return werklijstPanel.getWerklijstFilterPanel(); // This returns a panel with id `filterPanel`
}