ZK:关闭子窗口时刷新父窗口

  • 本文关键字:窗口 刷新 ZK zk
  • 更新时间 :
  • 英文 :


我想在 ZK 中实现以在关闭其子窗口的同时刷新父窗口。

Parent.zul - 这有一个下拉列表和一个按钮(标记为添加到下拉列表)来为此下拉列表添加值。 单击此按钮时,它应该会打开一个子 winow,其中包含在下拉列表中输入文本的选项。

child.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>

袜子控制器.java:公共类 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() 抛出 Exception{

@Listen("onClick = button#cancel")
public void onClickCancel() {
    manageLookup.setVisible(false);
    manageLookup.detach();
    Events.postEvent(Events.ON_CLOSE, windowOrSpaceOwner, someData);
}    

}

我将在这里向您展示我们应用程序的一些示例:

在父作曲器中,我们打开弹出窗口并为回调提供一个事件侦听器:

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);

我用这段代码和它在哪里工作创建了一个小提琴。
也许你可以看到你在哪里犯了错误?

希望这会有所帮助。

我假设您的子窗口是另一个具有模态属性的窗口,因此: 如果您使用的是 MVVM,则可以使用 GlobalCommand 来"刷新"父窗口。

在父窗口视图中,模型放置一个刷新下拉列表的方法,并在其中放置@GlobalCommand标记:

@GlobalCommand
public void refreshDropDown(){
    //Your code here
}

在子窗口中,如果您有关闭窗口的方法,则将调用添加到该 globalCommand:

public void closeWindow(){
    //your code to close the window here
    BindUtils.postGlobalCommand(null, null, "refreshDropDown", null);
}

或者直接在子窗口中 zul 中调用它:

<button label="Close window" onClick="@command('close') @global-command('refresh')" />

您可以在此处,此处和此处找到有关它的更多信息

最新更新