asked
2013-03-15 17:20:34 +0800
rickcr 704 ● 7 EDIT: updated:
NOTE: I can get binding to work if I try to wire up the div in the view model using @Wire and access it that way, but I'd like to know how to do it using selectors without having to use @Wire
Example of it working with @Wire (after running click on 'report builder'
http://zkfiddle.org/sample/3fdqtmj/12-GetPathIssues2#source-5
ORIGINAL POST:
I've looked over the docs here http://books.zkoss.org/wiki/ZKDeveloper'sReference/UIComposing/IDSpace but I'm still really confused what is going on here.
If you want to jump right to the example I created, I have it out here on zkfiddle (simplified to illustrate the issue)
http://zkfiddle.org/sample/3fdqtmj/8-GetPathIssues (I'll also post the code at the end of this post.)
I create a component and add it to a div section. That component added has its own viewmodel. It has a globalCommand and when that fires it tries to add something to its zul. However no matter how I try to access a component on this "inner" page, everything comes back null (the initial content loads just fine in the main content area as the demo above shows.) I even tried the utility class Terry posted here http://forum.zkoss.org/question/85149/pathgetcomponent-from-a-nested-component-cant-get-handle/ and if I try it in the globalCommand for reaching the page component //mainPage it's still null.
This is very confusing. On top of it, not related to getting the inner content but even the outer content with a structure as the following, You'd think I could get "contentSection" by /mainWindow/outer/contentSection.. but I can't! I have to use /mainWindow/contentSection. This has me really stumped as to why. Based on the docs, this doesn't look like it should be the case:
<window id="mainWindow" .../>
<div id="outer"><div height="100%" width="100%" id="contentSection"></div></div>
Here is the complete list of code, if you don't want to check out zkfiddle above...
<?page title="Test Get Path" id="mainPage"?>
<zk>
<window border="none" apply="org.zkoss.bind.BindComposer" id="mainWindow"
viewModel="@id('vm') @init('pkg$.MenuVM')" width="100%" height="100%">
<borderlayout height="100%">
<north size="67px" border="none"><div>NORTH</div></north>
<center border="none">
<div id="outer"><div height="100%" width="100%" id="contentSection"></div></div>
</center>
<west size="200px">
<vlayout>
<a label="Report Builder" onClick="@command('onShowContent',page='reportBuilder.zul')"/>
<a label="Page B" onClick="@command('onShowContent',page='pageB.zul')"/>
</vlayout>
</west>
</borderlayout>
</window>
</zk>
MenuVM
public class MenuVM {
@Command
public void onShowContent(@BindingParam("page") String page) {
//note why can't you use /mainWindow/outer/contentSection
Component comp = Path.getComponent("/mainWindow/contentSection");
comp.getChildren().clear();
Executions.createComponents(page, comp, null);
if (page.equals("reportBuilder.zul")) {
BindUtils.postGlobalCommand(null, null, "loadContent", null);
}
}
}
reportBuiler.zul
<div id="reportBuilder" apply="org.zkoss.bind.BindComposer" height="100%" width="100%"
viewModel="@id('vm') @init('pkg$.ReportBuilderVM')">
<div id="reportPageContent" height="100%" width="100%"><div>STUFF REPLACED WITH REPORT</div></div>
</div>
ReportBuilderVM
public class ReportBuilderVM {
@GlobalCommand
public void loadContent() {
Component comp = Path.getComponent("/reportPageContent");
//tried others Component comp = Path.getComponent("//mainPage/reportPageContent");
//HOW DO I GET ACCESS TO "reportPageContent" section to add a component to?????
Messagebox.show("Comp = "+comp, "Component Info", Messagebox.OK, Messagebox.INFORMATION);
Executions.createComponents("report.zul", comp, null);
}
}