Zk如何通过id到达包含的.zul页面组件?

Erc*_*can 2 include zk

我无法在包含的.zul页面中通过id访问组件.我有一个带控制器的main.zul,我需要通过java控制器类在包含的zul页面中获取一个组件,但它返回null.

我知道include方法创建了新的id空间,但有没有办法获得这个组件?

UPDATE

这是我的代码:

主要的zul页面

<?page title="DealerVizard.zul"?>

<?page id="main" ?>

<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="./Dealer" ?>
<zk>
    <style src="/resources/css/default.css" />
    <window id="Dealer" class="index" 
        apply="com.i2i.prm.controller.IndexController">


        <div class="content" width="100%">

            <tabbox id="tb" forward="onSelect=onSelect">
                <tabs id="tabs">
                    <tab id="info" label="INFO" />
                    <tab id="create" label="CREATE" />
                    <tab id="edit" label="EDIT" />
                    <tab id="test" label="TEST PANEL(LIST BOX)" />

                </tabs>
                <tabpanels>
                    <tabpanel id="DealerInfo">
                        <include id="DealerInfoContent"
                            src="View/Dealer/DealerInfo.zul" />
                    </tabpanel>
                    <tabpanel id="DealerCreate">
                        <include id="DealerCreateContent"
                            src="View/Dealer/DealerCreate.zul" />
                    </tabpanel>
                    <tabpanel id="DealerEdit">
                        <include id="DealerEditContent"
                            src="View/Dealer/DealerEdit.zul" />
                    </tabpanel>

                    <tabpanel id="PagingListBox">
                        <include  id="PagingListBoxContent"  // Included here
                            src="View/TEST/PagingListBox.zul" />
                    </tabpanel>
                </tabpanels>
            </tabbox>
        </div>
    </window>

</zk>
Run Code Online (Sandbox Code Playgroud)

PagingListBox.zul(包含页面)

<?page id="list" ?>

<zk>

    <grid width="100%">

        <columns>
            <column label="" />

        </columns>
        <rows>
            <row>
                <listbox id="listModel" width="100%" height="100%"
                    visible="true" span="true" pagingPosition="top" rows="20"
                    selectedItem="@{DealerController.selected}"
                    model="@{DealerController.userList}"
                    forward="onSelect=//main/Dealer.onSelect">
                    <auxhead>
                        <auxheader colspan="1">
                            <textbox
                                value="@{DealerController.searchUser.name}" maxlength="9"
                                id="searchCO_ID" forward="onChanging=//main/Dealer.onSearch"
                                width="100%">
                            </textbox>
                        </auxheader>
                        <auxheader colspan="1">
                            <textbox
                                value="@{DealerController.searchUser.surname}" maxlength="21"
                                id="searchMSISDN" forward="onChanging=//main/Dealer.onSearch"
                                width="100%">
                            </textbox>
                        </auxheader>
                        <auxheader colspan="1">

                        </auxheader>

                    </auxhead>

                    <listhead>
                        <listheader label="Name"
                            sort="auto(UPPER(name))" />

                        <listheader label="Surname"
                            sort="auto(UPPER(surname))" />


                        <listheader label="Delete ?" />
                    </listhead>


                    <listitem self="@{each=USERLIST}">

                        <listcell>
                            <label value="@{USERLIST.user.name}" />
                            <textbox
                                value="@{DealerController.tmpUser.name}" visible="false" />
                        </listcell>
                        <listcell>
                            <label value="@{USERLIST.user.surname}" />
                            <textbox
                                value="@{DealerController.tmpUser.surname}" visible="false" />
                        </listcell>

                        <listcell>
                            <button label="Update"
                                forward="onClick=//main/Dealer.onUpdate" visible="false" />
                            <button image="icons/edit-delete.png"
                                label="Delete" forward="onClick=//main/Dealer.onDelete"
                                width="100%" disabled="true" />
                            <button label="Save"
                                forward="onClick=//main/Dealer.onSave" visible="false" />
                            <button label="Cancel"
                                forward="onClick=//main/Dealer.onCancel" visible="false" />
                        </listcell>
                    </listitem>
                </listbox>
                <paging id="pagingData" pageSize="20" />
            </row>

        </rows>
    </grid>
</zk>
Run Code Online (Sandbox Code Playgroud)

IndexCOntroller.java

public class IndexController extends  GenericForwardComposer  {

    private List<User> userList = new ArrayList<User>() ;
    AnnotateDataBinder binder;
    Tabbox tb;
    Window Dealer;
    private int pageCount=0;

    @Override
    public void doAfterCompose(Component comp) throws Exception {
        // TODO Auto-generated method stub
        super.doAfterCompose(comp);
        comp.setVariable(comp.getId() + "Controller", this, true);
        binder = (AnnotateDataBinder) Dealer.getVariable("binder", true);


    System.out.println(Path.getComponent("//list/listModel"));
    }


    public IndexController() {
        // TODO Auto-generated constructor stub
    }
}
Run Code Online (Sandbox Code Playgroud)

kac*_*mbu 6

通常,我不建议使用Path.getComponent()方式访问其他组件,因为您的应用程序代码与视图页面中的组件结构紧密耦合.在你的情况下,你最简单的方法是使用AbstractComponent#getFellow(String compId)方法,例如.

Include inc = (Include) Dealer.getFellow("PagingListBoxContent");
Listbox listModel = (Listbox) inc.getFellow("listModel");
System.out.println(listModel);
Run Code Online (Sandbox Code Playgroud)

因此,将来即使您在列表框之前在ZUML页面中插入任何其他组件,您的代码仍然可以工作.

更新:BTW 最近在ZK博客上有一篇关于这个话题的有趣博客文章