0

More major getComponent() confusion???? [closed]

asked 2013-03-15 17:20:34 +0800

rickcr gravatar image rickcr
704 7

updated 2013-03-15 19:03:49 +0800

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);
}
    }
delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by rickcr
close date 2013-03-19 04:18:36

2 Answers

Sort by ยป oldest newest most voted
1

answered 2013-03-18 10:41:26 +0800

vincentjian gravatar image vincentjian
2245 6

updated 2013-03-19 01:03:57 +0800

Hi rickcr, Window component implements IdSpace, so you have to get the "reportPageContent" component with path "/mainWindow/reportPageContent".

First:

Component comp = Path.getComponent("/reportPageContent");

There is no component that implements IdSpace here, so you get null.

Second:

Component comp = Path.getComponent("//mainPage/reportPageContent");

mainPage implements Idspace of course, but under this Idspace, there is no component which id named "reportPageContent", that's why you get null again. By looking from page the path should be "//mainPage/mainWindow/reportPageContent".

Third:

Path.getComponent() API is used for looking fellow component under Idspace, where fellow means all components under Idspace are on equal level, you don't need to consider their parent-child relation. The parent-child relation only works between Idspaces.

Finally, with correct path defined, you don't need @Wire annotation.

Hope my explanation is clear enough.

link publish delete flag offensive edit

Comments

vincentijan look at my comment in the ReportBuilderVM, http://zkfiddle.org/sample/3fdqtmj/8-GetPathIssues#source-5 I had tried exactly that //mainPage/rpeortPageContent and it hadn't worked. Could you fork zkfiddle link I just posted and demonstrate it working using //mainPage ?

rickcr ( 2013-03-18 13:47:45 +0800 )edit

Like I said, if you want to find the component start from page, the correct path is "//mainPage/mainWindow/reportPageContent". You can't skip the window component.

vincentjian ( 2013-03-19 01:01:18 +0800 )edit

My bad! I totally missed you added "myWindow" in there! Thank you for replying !

rickcr ( 2013-03-19 04:16:52 +0800 )edit
0

answered 2013-03-15 17:48:00 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

See this Zk Fiddle Demo Updated version is this help you as i just updated your code ..i am not clear the whole requirement or not able to get the question but you can check if solve your issue

link publish delete flag offensive edit

Comments

That sjoshi get's me closer (I think) but in your example the next step is to load "report.zul" in the "reportPageContent" section on reportBuilder.zul which its not doing. It likes like in your fiddle mod you're trying to attach to the view in general but not to the "reportPageContent" section?

rickcr ( 2013-03-15 18:50:15 +0800 )edit

May be because you used if (page.equals("reportBuilder.zul")) {

        BindUtils.postGlobalCommand(null, null, "loadContent", null);
    }SO it will load only one page
sjoshi ( 2013-03-15 19:27:41 +0800 )edit

but loadContent fires just fine in the GlobalCommand listener in ReportBuilderVM. (I only care about it loading that one page for this example.) It's just not loading report.zul into the "/reportPageContent" in either your approach or mine.

rickcr ( 2013-03-16 01:15:55 +0800 )edit

Question tools

Follow
2 followers

RSS

Stats

Asked: 2013-03-15 17:20:34 +0800

Seen: 38 times

Last updated: Mar 19 '13

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