ZK - Open Source Ajax Java FrameworkZK - Open Source Ajax Java Framework

One composer applied to two pages

Jezreel
8 Feb 2012 07:48:07 GMT
8 Feb 2012 07:48:07 GMT

Dear all:

I have bumped into a problem and could not find help after searching through the tech documents and forum.

Here is my case:
(please ignore any possible syntax errors, i illustrated them for convenience reasons)

Two separate zul files (zul_1, zul_2)
In zul_1
<window>
<include id="zul_2"/>
</window>
in both zul_1 & zul_2, i applied the same controller
My goal: event occurs in zul_2 will change the contents in zul_1 (a typical inter-page communication)

However, the approach of having one controller for two zul files is not so convincing :
it makes the composer a bit messy. However it works when an event occurs on a textbox in zul_2, the event listener implemented
in the controller responds but would not do anything to the textbox in zul_2 while it does to textbox in zul_1.
I checked in different docs and thought how i declared the textbox in zul_2 may be wrong but tried many ways, still
could not get it work.

in zul_1
<textbox id="cleared">
in zul_2
<textbox id="something">

in composer:
textbox something, cleared;

void onFocus$something(){
//does something to textbox cleared
cleared.setValue(" "); //this works
something.setValue(" "); //doesnot work
}

then i tried:
textbox cleared;
textbox zul_2$something;

void onFocus$something$zul_2(){
//does something to textbox cleared
cleared.setValue(" "); //this works
zul_2$something.setValue(" "); // still doesnot work
}

Please, can anyone help

ashishd
8 Feb 2012 08:30:43 GMT
8 Feb 2012 08:30:43 GMT

First of all this is a wrong programming model. One composer should not be applied to two components. The reason being ZK will create two separate instances of composer and each will have only components autowired from the page it was applied to. For eg. If you have MyComposer applied to zul1 and zul2 where zul1 contains textbox1 and zul2 contains textbox2. Now even if you have declared textbox1 and textbox2 as fields of MyComposer there will be two instances of MyComposer when you load zul1 and zul2 in browser. One instance will have textbox1 pointing to correct component but textbox2 will be null where are instance2 will have the other way around.

Second, what is the use case and why do you need to use same composer for two functionally different pages?