首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Zk如何通过id到达包含.zul页面组件?

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

Stack Overflow用户
提问于 2011-07-12 08:55:28
回答 4查看 19.9K关注 0票数 3

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

我知道包含的方法会创建新的id空间,但是有什么方法可以获得这个组件吗?

更新

这是我的代码:

主页

代码语言:javascript
复制
<?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>

PagingListBox.zul (包括页面)

代码语言:javascript
复制
<?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>

IndexCOntroller.java

代码语言:javascript
复制
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
    }
}
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2011-07-13 02:43:32

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

代码语言:javascript
复制
Include inc = (Include) Dealer.getFellow("PagingListBoxContent");
Listbox listModel = (Listbox) inc.getFellow("listModel");
System.out.println(listModel);

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

UPDATE:顺便说一下,最近ZK博客上有一个有趣的博客

票数 8
EN

Stack Overflow用户

发布于 2011-07-15 11:04:33

如果包含有id,则可以使用美元符号获取内部组件。

代码语言:javascript
复制
  <zk>
  <include id="inc" src="test.zul />

  </zk>

test.zul

代码语言:javascript
复制
    <zk>
    <label id="lab1" value="test1" />
    </zk>

您可以使用"inc$lab1“在test.zul中获取标签

票数 1
EN

Stack Overflow用户

发布于 2011-07-12 09:34:28

您可以使用zscript或java访问任何其他id空间中的任何组件。如果在同一页上,但在不同的窗口上,则(窗口A中的组件B):

代码语言:javascript
复制
Path.getComponent("/A/B");

如果是在另一页上(P页窗口A中的组件B):

代码语言:javascript
复制
Path.getComponent("//P/A/B");

您可以在这里找到文档:http://books.zkoss.org/wiki/ZK%20Developer%27s%20Reference/UI%20Composing/ID%20Space

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6661675

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档