0

How a parent can catch an event of its child?

asked 2010-08-03 04:45:36 +0800

SHERKHAN gravatar image SHERKHAN
231 3

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

delete flag offensive retag edit

8 Replies

Sort by ยป oldest newest

answered 2010-08-03 04:50:18 +0800

SHERKHAN gravatar image SHERKHAN
231 3

updated 2010-08-03 04:53:31 +0800

Maybe ? :

 public void onClose() {
    	Events.postEvent(EVENT_ON_CLOSE_SERVICE, this.self.getParent, null);
    }

I am just testing, and it doesn't work too...

link publish delete flag offensive edit

answered 2010-08-03 05:11:19 +0800

iantsai gravatar image iantsai
2755 1

you have a public void onClose() method declaration, I presumed this is a event listening method and I'm wondering which component is it's host?

link publish delete flag offensive edit

answered 2010-08-03 05:16:54 +0800

vinhvo gravatar image vinhvo
369 3

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

I did something like this in parent:
	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

}

in child:
Events.postEvent("onModalExit", self, null);
		self.detach();

link publish delete flag offensive edit

answered 2010-08-03 05:18:20 +0800

vinhvo gravatar image vinhvo
369 3

Also, according to @iantsai: can you check if your onClose really get executed.

link publish delete flag offensive edit

answered 2010-08-03 05:22:28 +0800

SHERKHAN gravatar image SHERKHAN
231 3

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

link publish delete flag offensive edit

answered 2010-08-03 05:33:19 +0800

SHERKHAN gravatar image SHERKHAN
231 3

updated 2010-08-03 06:51:32 +0800

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

link publish delete flag offensive edit

answered 2010-08-27 06:00:43 +0800

Kuldeep gravatar image Kuldeep
33

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.

link publish delete flag offensive edit

answered 2010-08-27 15:44:16 +0800

enix0907 gravatar image enix0907
129 1
http://sites.google.com/s...

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>


SearchScholarship.zul
<?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>


form_ScholarshipApp.zul
<?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>


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


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

	}

}

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-08-03 04:45:36 +0800

Seen: 931 times

Last updated: Aug 27 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More