0

Weird Controller problem

asked 2011-11-27 06:10:17 +0800

pdavie gravatar image pdavie
97 3

updated 2011-11-27 06:11:57 +0800

I have a complex screen, which has a different controller for different parts of the screen.

I've used the

self.getDesktop.setAttribute(...)
approach to sharing controller information between the different controllers, since they need to interact.

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

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2011-11-27 06:32:44 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

updated 2011-11-27 06:55:13 +0800

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

ZKFiddle-Link

TestComposerTwo.java
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);
}
}


TestComposer.java
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);
}
}


index.zul
<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

link publish delete flag offensive edit

answered 2011-11-27 06:45:21 +0800

pdavie gravatar image pdavie
97 3

updated 2011-11-27 06:47:40 +0800

I've used

public void doBeforeComposeChildren(Component comp) throws Exception
instead, since I only need to do a one off setup.

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) ;
which works.
Thanks for pointing me in the right direction!

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: 2011-11-27 06:10:17 +0800

Seen: 196 times

Last updated: Nov 27 '11

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