在renderHead中运行javascript,并将markupId作为Wicket中的参数
我有一个面板“MainPanel”和组件“MyComponent”。我想将组件的markupId作为javascript函数中的参数传递,该函数将在renderHead()中调用。怎么做在renderHead中运行javascript,并将markupId作为Wicket中的参数,java,wicket,Java,Wicket,我有一个面板“MainPanel”和组件“MyComponent”。我想将组件的markupId作为javascript函数中的参数传递,该函数将在renderHead()中调用。怎么做 public MainPanel(String id) { super(id); MyComponent div = new MyComponent("div"); div.setmarkupId("customeUniqu
public MainPanel(String id) {
super(id);
MyComponent div = new MyComponent("div");
div.setmarkupId("customeUniqueId");
div.add(new AjaxEventBehavior("click") {
@Override
protected void onEvent(AjaxRequestTarget target) {
String markupId = div.getMarkupId();
target.appendJavaScript("window.location.reload();");
target.appendJavaScript(jsReload(markupId));
}
}
}
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
// how to use here div.markupId value as a parameter???
response.render(OnDomReadyHeaderItem.forScript(String.format("my_js_callback('%s')", div.getMarkupId())));
}
}
首先,您需要将div添加到主面板:
add(div)代码>。我猜您的代码中已经有了它,但在显示的代码片段中缺少了它
然后可以使用get(“div”).getMarkupId()
访问div
,即获取id为“div”的子项。另一种方法是提取MyComponent div
作为MainPanel
类的成员字段,然后只使用div.getMarkupId()
您对id为“div”的get child意味着什么?在这次调用之后,我得到了一个错误get(“div”).getMarkupId()