ZK: 刷新parent window 同时关闭child window
ZK: Refreshing parent window while closing child window
我想在 ZK 中实现在关闭 child window 时刷新 parent window。
Parent.zul - 这有一个下拉列表和一个按钮(标记为添加到下拉列表)以向该下拉列表添加值。单击此按钮时,它应该会打开一个 child 窗口,其中包含一个用于在下拉列表中输入文本的选项。
child.zul :它有一个用于为下拉列表输入值的文本框和一个 "CLOSE" 按钮。单击关闭按钮时,它应该关闭 child window 并刷新 parent window 中的下拉菜单。
提前感谢您的意见。
============================================= =============================
Parent: 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 class 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();
}
}
}
child : 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);
}
}
我假设你的 child window 是另一个 window 模态 属性,所以:如果你正在使用 MVVM,你可以使用 GlobalCommand 来 "refresh" 你的 parent window.
在您的 parent window viewModel 中放置一个方法来刷新您的下拉列表并在其中放入 @GlobalCommand 标签:
@GlobalCommand
public void refreshDropDown(){
//Your code here
}
并且在您的 child window 中,如果您有关闭 window 的方法,则添加对该 globalCommand 的调用:
public void closeWindow(){
//your code to close the window here
BindUtils.postGlobalCommand(null, null, "refreshDropDown", null);
}
或者直接在您的 child window zul 中调用它:
<button label="Close window" onClick="@command('close') @global-command('refresh')" />
我将在这里向您展示我们应用程序的一些示例:
在 Parent 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 中实现在关闭 child window 时刷新 parent window。
Parent.zul - 这有一个下拉列表和一个按钮(标记为添加到下拉列表)以向该下拉列表添加值。单击此按钮时,它应该会打开一个 child 窗口,其中包含一个用于在下拉列表中输入文本的选项。
child.zul :它有一个用于为下拉列表输入值的文本框和一个 "CLOSE" 按钮。单击关闭按钮时,它应该关闭 child window 并刷新 parent window 中的下拉菜单。
提前感谢您的意见。
============================================= =============================
Parent: 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 class 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();
}
}
}
child : 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);
}
}
我假设你的 child window 是另一个 window 模态 属性,所以:如果你正在使用 MVVM,你可以使用 GlobalCommand 来 "refresh" 你的 parent window.
在您的 parent window viewModel 中放置一个方法来刷新您的下拉列表并在其中放入 @GlobalCommand 标签:
@GlobalCommand
public void refreshDropDown(){
//Your code here
}
并且在您的 child window 中,如果您有关闭 window 的方法,则添加对该 globalCommand 的调用:
public void closeWindow(){
//your code to close the window here
BindUtils.postGlobalCommand(null, null, "refreshDropDown", null);
}
或者直接在您的 child window zul 中调用它:
<button label="Close window" onClick="@command('close') @global-command('refresh')" />
我将在这里向您展示我们应用程序的一些示例:
在 Parent 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 以及它的工作原理。
或许你能看出哪里出错了?
希望对您有所帮助。