-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I'm using apply and forward, but it doesn't work in that code:
<div class="div_outer" id="div_outer" apply="InputComposer2"> <vbox> <window id="win" title="parametry2" border="normal"> <button id="ok" label="OK" forward="onClick=div_outer.onOK" /> </window> <separator /> </vbox> </div>
<window id="win" title="parametry2" border="normal" apply="InputComposer2"> <button id="ok" label="OK" forward="onClick=win.onOK" /> </window>
Hi marioosh,
Some components are called space owners this components owns their children, which means that the children is in the "scope" of it's owner. Window is a space owner component and that's why the composer applied to Div doesn't see the components inside the window.
See Component path and accesibility
Regards,
Hi fmcypriano,
Thanks for replay :)
So... Composer can see win, but not inside win, because win is space owner. Something like that, yes ?
If Composer is applied (by apply="") to some element, it can see only their children (space owner too), but not children of that space owners, yes ?
If that's true, so... How can i easy handle onClick my "OK" button in InputComposer2 (extends GenericForwardComposer) ? Is that possible or i have to use apply in window (id=win) ?
<div id="div_outer" apply="comps.InputComposer2"> <vbox> <window id="win"> <button id="ok" label="OK" /> </window> ...
For an easioer handling you can extends from this GFCBaseCtrl class. It's used with the apply="" in the zul-file.
In your controller call the doOnCreateCommon(myWindow, event) in your onCreate$myWindowZul(Event event)
public class OrderListCtrl extends GFCBaseCtrl implements Serializable { private static final long serialVersionUID = 5710086946825179284L; private transient static final Logger logger = Logger.getLogger(OrderListCtrl.class); /* * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * All the components that are defined here and have a corresponding * component with the same 'id' in the zul-file are getting autowired by our * 'extends GFCBaseCtrl' GenericForwardComposer. * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ protected transient Window orderListWindow; // autowired ... public void onCreate$orderListWindow(Event event) throws Exception { if (logger.isDebugEnabled()) { logger.debug("--> " + event.toString()); } /* autowire comps the vars */ doOnCreateCommon(orderListWindow, event); ... // check if the orderList is called with a customer param if (args.containsKey("customerDialogCtrl")) { hBoxCustomerSearch.setVisible(false); } else { hBoxCustomerSearch.setVisible(true); } ...
The BaseGenericForwarderComposer
abstract public class GFCBaseCtrl extends GenericForwardComposer implements Serializable { private transient static final Logger logger = Logger.getLogger(GFCBaseCtrl.class); private static final long serialVersionUID = -1171206258809472640L; protected transient AnnotateDataBinder binder; protected transient Map<String, Object> args; public void doOnCreateCommon(Window w) throws Exception { binder = new AnnotateDataBinder(w); binder.loadAll(); } @SuppressWarnings("unchecked") public void doOnCreateCommon(Window w, Event fe) throws Exception { doOnCreateCommon(w); CreateEvent ce = (CreateEvent) ((ForwardEvent) fe).getOrigin(); args = ce.getArg(); } }
if you will work with the use="" in your zul-file you can extend from this WindowBaseController
It have the same call doOnCreateCommons() in the onCreate$myWindowZulFile() as the Composer above.
public abstract class WindowBaseCtrl extends Window implements AfterCompose, Serializable { private static final long serialVersionUID = -2179229704315045689L; protected transient AnnotateDataBinder binder; protected transient Map<String, Object> args; public void doOnCreateCommon(Window w) throws Exception { binder = new AnnotateDataBinder(w); binder.loadAll(); } @SuppressWarnings("unchecked") public void doOnCreateCommon(Window w, Event fe) throws Exception { doOnCreateCommon(w); CreateEvent ce = (CreateEvent) ((ForwardEvent) fe).getOrigin(); args = (Map<String, Object>) ce.getArg(); } public WindowBaseCtrl() { super(); this.setStyle("body {padding 0 0;}"); } @Override public void afterCompose() { processRecursive(this, this); // Components.wireVariables(this, this); // auto wire variables // Components.addForwards(this, this); // auto forward } /** * Go recursive through all founded components and wires all vars and added * all forwarders for ALL window components. <br> * * @param main * @param child */ @SuppressWarnings("unchecked") private void processRecursive(Window main, Window child) { Components.wireVariables(main, child); Components.addForwards(main, this); List<Component> winList = (List<Component>) child.getChildren(); for (Component window : winList) { if (window instanceof Window) { processRecursive(main, (Window) window); } } } }
best
Stephan
Stephen... I think, that is too complicated for beginner like me ;)
I have another question:
If i include a page like above, and use apply with GenericForwardComposer (or GenericAutowireComposer),
in ui.IndexPageComposer i can't access elements from included page. Why ?
<window id="indexWin" title="zpark" border="normal" apply="ui.IndexPageComposer"> <include id="ilogin" src="login.zul" /> <include id="icontent" src="content.zul" /> </window> public class IndexPageComposer extends GenericForwardComposer { private Include icontent; private Include ilogin; private Window content; // <---- that is not autowired, why ? public void doAfterCompose(Component indexWin) throws Exception { super.doAfterCompose(indexWin); System.out.println(content.getId()); // error! } } content.zul: <window id="content"> content here </window>
Because it's in another space owner. You should read the document that I posted in a earlier post to understand how it work, and also read ZK fundamentals.
To get a component from another space owner you can use Path.getComponent("path here"), this is described in the link Component path and accessibility. After you get the component you can add event to to using component.addEventListener("onClick", eventListener).
Also you can use other composers, for example the window component inside you content.zul could have it's own composer.
Regards,
Why in another space owner? In which space owner? Include is a space owner ?
I understand that content window that is defined in content.zul is another space owner, and i can't get his children, but i need to get only that window in my composer.
I've readed about Path, but i get error in IndexPage composer:
index.zul: <?page title="zpark" id="pindex"?> <zk> <style src="css/style.css" /> <div class="div_outer" id="div_outer"> <vbox width="800px"> <window id="indexWin" title="zpark" border="normal" apply="ui.IndexPage"> <include id="ilogin" src="login.zul" /> <separator/> <include id="icontent" sclass="test" src="content.zul" /> </window> </vbox> </div> </zk> content.zul: <?page title="zpark" id="pcontent"?> <zk> <window id="content" title="content" border="normal"> New Content Here! </window> </zk> IndexPage.java: public class IndexPage extends GenericForwardComposer { private Include icontent; private Include ilogin; private Window content; public void doAfterCompose(Component indexWin) throws Exception { super.doAfterCompose(indexWin); content = (Window)Path.getComponent("//pcontent/content"); System.out.println(content.getId()); // error, why ? } public void onClick$icontent() { System.out.println("click icontent"); } public void onClick$content() { System.out.println("click content win"); } }
Man, why don't read the links I'm posting? It's not so hard to do, you need to understand the technology you're using no matter if it's ZK or java or .Net, read the docs.
<window id="indexWin" apply="ui.IndexPageComposer"> <include id="ilogin" src="login.zul" /> <include id="icontent" src="content.zul" /> </window> public class IndexPageComposer extends GenericForwardComposer { private Include icontent; private Include ilogin; private Window content; // <---- that is not autowired, why ?
It's not autowired because the window called content does not belongs to the window called indexWin.
You can access any component in any space owner (like window) using this code:
Window windowInsideInclude = (Window) Path.getComponent("/indexWin/ilogin/content");
Another option is to use a new composer for the content window:
<window id="indexWin" title="zpark" border="normal" apply="ui.IndexPageComposer"> <include id="ilogin" src="login.zul" /> <include id="icontent" src="content.zul" /> </window> content.zul: <window id="content" apply="AnotherComposer"> content here </window> public class AnotherComposer extends GenericForwardComposer { private Window content; public void doAfterCompose(Component indexWin) throws Exception { super.doAfterCompose(indexWin); System.out.println(content.getId()); } }
All the links that I've posted you guide to you understand this options, you must read them.
Regards,
fmcypriano, thanks for Your patience.
I've readed Your links... and want to use Path.getComponent... but something doesn't work :/
If i have page.zul like this:
<?page title="zpark" id="pcontent"?> <window id="content" title="content" border="normal"> </window>
Is that true, that by using Path.getComponent("//pcontent/content") in ANYWHERE (any composer etc) i can get my content Window ?
Yes, assuming the page pcontent exists (it's loaded) when you try to access it.
And what if i include my page.zul in some another page2.zul... Is Path.getComponent("//pcontent/content") will be work to ?
Good question I never tried it before.
Another option would be to not use the page id, like:
page.zul
<window id="content" title="content" border="normal"> </window>
page2.zul
<window id="wndPage2" apply="Page2Composer"> <include id="include" src="page.zul" /> </window> // in the composer Path.getComponent("/wndPage2/include/content");
Hope it help,
Asked: 2009-11-25 07:16:06 +0800
Seen: 1,292 times
Last updated: Nov 27 '09