我想在ZK中实现在关闭子窗口的同时刷新父窗口。
Parent.zul - 它有一个下拉列表和一个按钮(标签为“添加到下拉列表”),用于向该下拉列表添加值。单击此按钮时,它应该打开一个子窗口,其中包含在下拉列表中输入文本的选项。
child.zul:它有一个用于输入下拉列表值的文本框和一个“关闭”按钮。单击关闭按钮时,它应该关闭子窗口并刷新父窗口中的下拉列表。
预先感谢您的意见。
================================================== ===========================
父级:sock.zul
<window id="sockWindow" title="New Sock" width="600px" apply="SockController" mode="modal" closable="true">
<div align="left" style="float: left;" >
<button id="btnLookup" label="Manage Lookup" width="150px"/>
</div>
</window>
sockController.java: 公共(public)类 SockController 扩展了 SelectorComposer {
@Listen("onClick = button#btnLookup")
public void onClickAdd() throws Exception {
showPopup(new EventListener<Event>() {
@Override
public void onEvent(final Event event) throws Exception {
Object someData = event.getData(); // cast to whatever object you expect to give.
//Make your refresh code here.
}
});
}
public static void showPopup(final EventListener<Event> eventListener)
throws InterruptedException {
//you can give more params with the method to add them as arguments.
Map arguments = new HashMap<String, String>();
arguments.put("source", "parent.zul");
// arguments.put("hid", hwid.toString());
// arguments.put("displaymode", displaymode);
openModal("/managelookup.zul",null, arguments, eventListener);
}
public static void openModal(final String page, final Component parent,
final Map<String, Object> obMap,
final EventListener<Event> onCloseListener)
throws InterruptedException {
for (final Map.Entry<String, Object> entry : obMap.entrySet()) {
Executions.getCurrent().setAttribute(entry.getKey(),
entry.getValue());
}
Executions.getCurrent().setAttribute(Composition.PARENT, null);
final Component createComponents = Executions.createComponents(page,
parent, obMap);
Component parent1 = createComponents;
parent1 = getWindow(parent1);
if (parent1 instanceof Window) {
final Window window = (Window) parent1;
if (onCloseListener != null) {
//attach the listener so when popup is closed the listener is called.
window.addEventListener(Events.ON_CLOSE, onCloseListener);
window.addEventListener(Events.ON_CANCEL, onCloseListener);
}
window.doModal();
}
}
}
子:managelookup.zul:
<button id="cancel" label="Close"/>
</window>
ManageLookupsController.java: public ManageLookupsController() 抛出异常{
@Listen("onClick = button#cancel")
public void onClickCancel() {
manageLookup.setVisible(false);
manageLookup.detach();
Events.postEvent(Events.ON_CLOSE, windowOrSpaceOwner, someData);
}
}
最佳答案
我将在这里向您展示我们应用程序的一些示例:
在父 Composer 中,我们打开弹出窗口并为回调提供一个事件监听器:
public void onActionShowPopup () {
showPopup(new EventListener<Event>() {
@Override
public void onEvent(final Event event) throws Exception {
Object someData = event.getData(); // cast to whatever object you expect to give.
//Make your refresh code here.
}
});
}
public static void showPopup(final EventListener<Event> eventListener)
throws InterruptedException {
//you can give more params with the method to add them as arguments.
final Map<String, Object> args = new HashMap<>();
args.put("modus", "modal");
openModal("/WEB-INF/webpages/zk/popup/some_popup.zul",null, args, eventListener);
}
public static void openModal(final String page, final Component parent,
final Map<String, Object> obMap,
final EventListener<Event> onCloseListener)
throws InterruptedException {
for (final Map.Entry<String, Object> entry : obMap.entrySet()) {
Executions.getCurrent().setAttribute(entry.getKey(),
entry.getValue());
}
Executions.getCurrent().setAttribute(Composition.PARENT, null);
final Component createComponents = Executions.createComponents(page,
parent, obMap);
Component parent1 = createComponents;
parent1 = getWindow(parent1);
if (parent1 instanceof Window) {
final Window window = (Window) parent1;
if (onCloseListener != null) {
//attach the listener so when popup is closed the listener is called.
window.addEventListener(Events.ON_CLOSE, onCloseListener);
window.addEventListener(Events.ON_CANCEL, onCloseListener);
}
window.doModal();
}
}
public Component getWindow (Component comp) {
if (comp != null && !comp instanceof Window) {
return getWindow(comp.getParent());
}
return comp;
}
当然,当你关闭时,在弹出窗口中:
Events.postEvent(Events.ON_CLOSE, windowOrSpaceOwner, someData);
我创建了a fiddle使用此代码及其工作位置。
也许你能看到哪里出错了?
希望这能有所帮助。
关于ZK:关闭子窗口时刷新父窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37717899/