-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi all,
Here is my problem : I would like catching in my Include object an event from its child.
Composer 1:
public void createWindowServiceForm(String id) throws SuspendNotAllowedException, InterruptedException { String src = "serviceFormPage.zul"; if (id != null && !id.isEmpty()) { src += "?serviceId=" + id; } final Include include = new Include(); include.setSrc(src); include.setPage(page); include.addEventListener(ServiceFormController.EVENT_ON_CLOSE_SERVICE, new EventListener() { @Override public void onEvent(Event event) throws Exception { include.detach(); } }); }
ServiceFormController:
public void onClose() { Events.postEvent(EVENT_ON_CLOSE_SERVICE, this.self, null); }
But as you can see, I don't catch anything... What is the solution?
Thanks for your help,
Ragards,
SHERKHAN
Maybe ? :
public void onClose() { Events.postEvent(EVENT_ON_CLOSE_SERVICE, this.self.getParent, null); }
I am just testing, and it doesn't work too...
Try this , and I bet the printed result is not include component
public void onClose() { System.out.println(this.self.getParent); Events.postEvent(EVENT_ON_CLOSE_SERVICE, this.self.getParent, null); }
Window editUserWin = (Window)Executions.createComponents("users/editUser.zul", null,map); editUserWin.setMaximizable(true); editUserWin.setClosable(true); editUserWin.addForward("onModalExit",self, "onRefresh"); editUserWin.doModal(); public void onRefresh(Event evt){//catch event }
Events.postEvent("onModalExit", self, null); self.detach();
Hi iantsai,
The include create a window (serviceFormPage.zul) :
The serviceFormPage.zul :
<?page id="ServiceForm" title="Service form" cacheable="false" language="xul/html" zscriptLanguage="Java"?> <?meta content="text/html; charset=UTF-8" pageEncoding="UTF-8"?> <window closable="true" maximizable="true" sizable="true" height="400px" width="200px" contentStyle="overflow:auto" apply="org.chorem.bonzoms.ui.ServiceFormController"> <caption label="Service"/> <groupbox> <caption label="Service informations" /> <vbox> <label value="Type" /> <textbox value="@{composer.service.type, save-when='saveService.onClick'}" /> <label value="Name" /> <textbox value="@{composer.address.name, save-when='saveService.onClick'}" /> <label value="Address 1" /> <textbox value="@{composer.address.address1, save-when='saveService.onClick'}" /> <label value="Address 2" /> <textbox value="@{composer.address.address2, save-when='saveService.onClick'}" /> <label value="Zip code" /> <textbox value="@{composer.address.zipCode, save-when='saveService.onClick'}" /> <label value="City" /> <textbox value="@{composer.address.city, save-when='saveService.onClick'}" /> <label value="Country" /> <textbox value="@{composer.address.country, save-when='saveService.onClick'}" /> </vbox> </groupbox> <button label="save" id="saveService" /> </window>
its Composer:
public class ServiceFormController extends GenericForwardComposer { protected Model model = new Model(); protected Service service = new ServiceImpl(); protected Address address = new AddressImpl(); public static final String EVENT_ON_SAVE_SERVICE = "onSaveService"; public static final String EVENT_ON_CLOSE_SERVICE = "onCloseService"; @Override public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); Window win = (Window) self; win.doModal(); win.setPosition("center"); String id = Executions.getCurrent().getParameter("serviceId"); if (id != null) { initService(id); } DataBinder binder = new AnnotateDataBinder(comp); binder.bindBean("composer", this); binder.loadAll(); } protected void initService(String id) { service = model.retrieveServiceById(id); address = model.retrieveAddressById(service.getAddress()); } /* * Events */ public void onClose() { Events.postEvent(EVENT_ON_CLOSE_SERVICE, this.self, null); } public void onClick$saveService() { address = model.createAddress(address); service.setAddress(address.getWikittyId()); service = model.updateService(service); Events.postEvent(EVENT_ON_SAVE_SERVICE, this.self, service); self.detach(); } /* * Getters */ public Service getService() { return service; } public Address getAddress() { return address; } }
Thanks for your help,
Best regards,
SHERKHAN
Hi vinhvo,
this.self.getParent() == null and the onClose method is called when I close the window... I have to use include because I will use Iframe to open the same zul page from another server :D.
Thanks for your help,
Best regards,
SHERKHAN
I am also facing the same issue.
I have a ZUL file that is having one included ZUL file in it.
If I postEvent from included ZUL on Include tag, then event listener of Include tag in parent ZUL is not executed.
Please help.
Hello all, I have overcome this problem in my code. You can find my solution in my following example. Then, you can see what I did before I pose an event to my main page.
Main page: including 2 other pages....
<?page id="index_page" title="Create your application" contentType="text/html;charset=UTF-8"?> <zk> <window apply="test.MainWinComposer" id="MainWin" border="normal" width="100%" height="auto" contentStyle="overflow:auto"> <button id="mybtn" label="index_page - getPage" /> <!--include component is a ID space Owner like Regular Macro and Window--> <include src="SearchScholarship.zul" /> <zscript><![CDATA[ System.out.println("form index_page: " + page.getId()); ]]></zscript> <include id="inc" src="form_ScholarshipApp.zul" /> </window> </zk>
<?page id="SearchScho" title="SearchScholarship" contentType="text/html;charset=UTF-8"?> <window id="FirstPage" apply="test.SearchSchoComposer"> <button id="mybtn" label="SearchScho - getPage" /> <zscript><![CDATA[ System.out.println("form SearchScho: " + page.getId()); ]]></zscript> </window>
<?page id="SchoAppForm" title="form_ScholarshipApp" contentType="text/html;charset=UTF-8"?> <window apply="test.SearchSchoComposer" id="SecondPage"> <button id="mybtn" label="SchoAppForm - getPage" /> <zscript><![CDATA[ System.out.println("form SchoAppForm: " + page.getId()); ]]></zscript> </window>
package test; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Path; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.util.GenericForwardComposer; import org.zkoss.zul.Button; public class SearchSchoComposer extends GenericForwardComposer { Button mybtn; public void doAfterCompose(Component win) throws Exception { super.doAfterCompose(win); System.out.println("doAfterCompose : " + self.getId()); } public void onCreate() { System.out.println(self.getId() + " onCreate : " + page.getId()); // System.out.println(page.getFellow("mainWin")); } public void onClick$mybtn() { Component comp = Path.getComponent("/MainWin"); if (comp != null) Events.postEvent(new Event("onDosometihng", comp, self)); } }
package test; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.util.GenericForwardComposer; public class MainWinComposer extends GenericForwardComposer { public void onDosometihng(Event eve) { Component InfoFromOtherPages = (Component) eve.getData(); alert("Triggered by my internal page: " + InfoFromOtherPages.getId()); } }
Asked: 2010-08-03 04:45:36 +0800
Seen: 931 times
Last updated: Aug 27 '10