我有这个HTML标记:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org/" xml:lang="cs" lang="cs">
<wicket:panel>
<div id="nav">
<ul>
<li>
<a href="./page2.html" class="here">page 1</a>
</li>
<li>
<a href="./page3.html" class="">page 2</a>
</li>
<li>
<a href="./kontakt.html" class="">page 3</a>
</li>
</ul>
</div>
</wicket:panel>
</html>
这是我面板的非常简单的wicket代码:
public class PanelMenu extends Panel{
private static final long serialVersionUID = 1L;
public PanelMenu(String id){
super(id);
}
}
@Override
protected void onBeforeRender(){
String markup = this.getAssociatedMarkup().toString();
markup = markup.replaceAll("a", "b");
//how to write modyfied markup for panel to response?
this.getResponse().write(markup);//this write to start of the page, not panel
super.onBeforeRender();
}
在我的页面上,我这样做:
this.add((new PanelMenu("panelMenu")).setRenderBodyOnly(true));
我需要知道如何为变量markup
中的面板编写modyfied html标记回到响应中。我该怎么做? this.getResponse().write(markup)
在页面开头写。
答案 0 :(得分:0)
您尝试将标记方式更改为延迟。要访问和修改组件标记,您必须通过实现自己的IResourceStream或扩展wickets MarkupResourceStream来执行修改,并在您在Application中设置的MarkupFactory中使用它。 init()as。
@Override
public void init() {
super.init();
getMarkupSettings().setMarkupFactory(new MyMarkupFactory());
}