-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have a complex screen, which has a different controller for different parts of the screen.
I've used the
self.getDesktop.setAttribute(...)
The structure of the ZUL file is like this:
WINDOW PANEL 1 PANEL 2 POPUP 1 POPUP 2 etc.
Each item has its own controller and can get a reference to the controllers for the other items fine.
The problem is this: ZK initializes the POPUP controllers BEFORE it calls the WINDOW controller. At least the doAfterCompose method of the WINDOW is called after the POPUP. This messes up my initialization code for the POPUP controllers, since they need access to a valid WINDOW controller.
In execution, it is impossible for the popups to execute before the window, so the problem is the initialization order of the page elements.
I've got a really ugly workaround to call an 'init' method at the top of each method in the popups, so it works, but it is ugly and unmaintainable and breaks good coding design totally.
Any suggestions would be very welcome.
Regards,
pdavie
Hi pdavie,
doAfterCompose will be called after all child is composed,
to do something before any child is composed, please use
public ComponentInfo doBeforeCompose(Page page, Component parent, ComponentInfo compInfo)
the simple sample below shows the init sequence
package j2n0lsfh$v1;import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.metainfo.ComponentInfo;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Label;
import org.zkoss.zul.Vbox;public class TestComposerTwo extends GenericForwardComposer {
Vbox msg;
public ComponentInfo doBeforeCompose(Page page, Component parent, ComponentInfo compInfo) {
msg = (Vbox)page.getFellow("msg");
Label l = new Label("-- child div before compose");
l.setParent(msg);
return super.doBeforeCompose(page, parent, compInfo);
}
public void doAfterCompose(Component comp) throws Exception {
Label l = new Label("--- child div after compose");
l.setParent(msg);
super.doAfterCompose(comp);
}
}
package j2n0lsfh$v1;import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.metainfo.ComponentInfo;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Label;
import org.zkoss.zul.Vbox;public class TestComposer extends GenericForwardComposer {
Vbox msg;
public ComponentInfo doBeforeCompose(Page page, Component parent, ComponentInfo compInfo) {
msg = (Vbox)page.getFellow("msg");
Label l = new Label("- window before compose");
l.setParent(msg);
return super.doBeforeCompose(page, parent, compInfo);
}
public void doAfterCompose(Component comp) throws Exception {
Label l = new Label("---- window after compose");
l.setParent(msg);
super.doAfterCompose(comp);
}
}
<zk>
<vbox id="msg">
<label value="The flow of init:" />
</vbox>
<window apply="j2n0lsfh$v1.TestComposer">
<div apply="j2n0lsfh$v1.TestComposerTwo"></div>
</window>
</zk>
Regards,
ben
I've used
public void doBeforeComposeChildren(Component comp) throws Exception
However, the problem I now get is that the "self' protected variable is not initialized yet. Which I use the set the controller value in the Desktop object.
I've tried
Executions.getCurrent().getDesktop().setAttribute(PARENT_CONTROLLER, dad) ;
Asked: 2011-11-27 06:10:17 +0800
Seen: 196 times
Last updated: Nov 27 '11