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

2024-02-27

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

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

UPDATE

这是我的代码:

祖尔主页

<?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(包含页面)

<?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>

IndexCOtroller.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
    }
}

通常我不建议使用Path.getComponent()当您的应用程序代码与视图页面中的组件结构紧密耦合时,访问其他组件的方式。 在你的情况下,你最简单的方法是使用AbstractComponent#getFellow(String compId) http://www.zkoss.org/javadoc/latest/zk/org/zkoss/zk/ui/AbstractComponent.html#getFellow%28java.lang.String%29方法如此,例如。

Include inc = (Include) Dealer.getFellow("PagingListBoxContent");
Listbox listModel = (Listbox) inc.getFellow("listModel");
System.out.println(listModel);

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

UPDATE: 顺便说一句,有一个有趣的blogpost http://blog.zkoss.org/index.php/2011/06/21/zk-demythtified-myth-i/ZK 博客上关于这个主题

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

  • 将支持 bean 作为参数传递给 Facelet include

    我有一个可以在不同应用程序中使用的 Facelet 我不是要复制它 而是重复使用它 我需要传递将管理视图的支持 bean 作为参数 因为某些逻辑可能会根据使用它的应用程序而有所不同 我不想使用复合组件 而只是包含 Facelet 并指定哪个
  • jQuery/JavaScript - 拥有大量小 .js 文件时的性能问题?

    我有一个包含大量引用的 js 文件的网站 这些是相当小的文件 但我想将我的方法按主题 功能分开 将所有方法保存在一个 js 文件中是否更好 或者拥有许多 20 30 个小文件都只包含一些行没有问题 无论如何 将它们分开进行开发 但您应该考虑
  • 多个定义和仅标头库

    我有一个带有几个 c 和 h 文件的 C 程序 我决定将程序的一部分设为 仅标头 因此我将代码从 c 移至 h 现在我遇到了多重定义问题 但我不知道为什么 例如 main c includes utils h vector c includ
  • jade/pug 是否可以在 include 语句中使用变量?

    我正在开发 Nodejs 应用程序 但我对 include 语句有疑问 当我像这样使用它时它会起作用 include mixins root pug 但是可以在包含中使用变量吗 这些都不起作用 include process env MIX
  • JSP处理指令未关闭

    我试图将 HTML 文件包含到我的 JSP 中 但我的 Eclipse 显示了此错误 包含的文件 和错误 Processing instruction not closed 这只是简单的 JSP
  • 记录 C 中“.h”文件使用模式的良好参考资料是什么? [复制]

    这个问题在这里已经有答案了 C 接口和实现 展示了一些有趣的数据结构使用模式 但我确信还有其他模式 http www amazon com Interfaces Implementations Techniques Addison Wesl
  • 实体框架代码优先 - 多对多 - 包括条件

    我有两个实体Store and Catalog 使用流畅的 Api 建立多对多关系 我想通过以下方式获得商店id所有目录的状态都等于 已发布 下面我尝试编写以下查询 但没有得到预期的结果 var store context Stores I
  • Qt Creator 代码编辑期间 CPU 为 100%

    我有 Qt Creator 项目 它用boost and Point Cloud library 当我编辑包含这些库中的内容的文件时 Qt Creator 在每次代码更改 添加行 更改变量类型等 后挂起大约 30 秒 TaskManager
  • linux/ext2_fs.h 有什么问题?

    猫主 c include
  • 包设置不会传播到分布式的工作人员

    Info julia version julia version 1 6 0 lscpu root MyPackage lscpu Architecture x86 64 CPU op mode s 32 bit 64 bit Byte O
  • 本地#includes

    有没有某种方法可以在本地 include 标准内容 一次针对一个函数 一个类等 而不是全局的 举一个非常简单的例子 人们可能想使用 std string 但它只在一个类中需要 并且您不希望它的开销无处不在 而不是制作 include本地 您
  • 通过 Jquery 从 Datebox 中清除日期

    下面的代码在日期框模式弹出窗口中显示一个按钮 但我想清除单击该按钮时的日期 我尝试了很多东西 但无法通过 jQuery 方法做到这一点
  • C++ 类,其基类和循环包含 [重复]

    这个问题在这里已经有答案了 文件 1 foo h ifndef FOO H define FOO H include baseclass h include bar h class Bar class Foo public baseclas
  • 如何在 PHP 中包含一个类 [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 我有文件index php 我想包含文件class twitter php在里面 我怎样才能做到这一点 希望当我将以下代码放入 index
  • 如何使用QtCopyDialog?

    我包括这个库 include
  • 实体框架 - 包含在子查询中?

    我不确定这个问题是否已经得到解答 我查看了几个问题 但我认为它们并不是我想要的 假设我有 3 张表 Restaurant 1 M MenuCategory 1 M MenuItem 我有一个 L2E 查询 如下所示 Restaurant c
  • 如何将 php 文件包含在主域的子域中

    我的服务器中有两个文件夹 MainDomain header php index php footer php Subdomain index php 现在我想包括header php来自主域index php这是在子域中 通过使用incl
  • 如何在 Jinja2 中包含具有相对路径的模板

    我正在尝试在模板中包含同一文件夹中的另一个模板 为此 我只是在做 import header jinja2 问题是我不断收到TemplateNotFound error 我的模板文件夹看起来像 myProject templates arb
  • 编译器处理包含保护头的开销有多大?

    为了加速大型源文件的编译 修剪翻译单元中使用的标头数量是否更有意义 或者编译代码的成本是否远远超过处理包含保护的时间标头 如果后者是真的 那么工程工作最好花在创建更多 轻量级的标头上 而不是更少 那么 现代编译器需要多长时间才能处理有效包含
  • 服务器端的 ASP.NET 等效项包括

    虽然服务器端包含的经典 ASP 方法在 ASP NET 中有效 但我的印象是它不是首选方法 我 应该 如何达到同样的效果 这就是我现在正在做的事情 您现在有许多选项可以提供这种效果 但方式不同 用户控件 ascx 母版页 master 服务

随机推荐