JAVA:ZK框架如何将两个bean设置为列表框?

发布于 2024-10-20 19:28:04 字数 4238 浏览 2 评论 0原文

我正在尝试制作可编辑的列表框,使用户能够更新列表项或取消它。但是我无法获取选定的项目以将其保存在另一个bean上,然后如果用户单击取消,则显示原始记录。这使我返回 null。

Listitem listitem =  self.getParent().getParent();
Listbox listbox = listitem.getListbox();
alert(listbox.getSelectedItem().getValue());

我还在 .zul 文件上使用 zscript 来进行此操作。这是我的列表框和更新功能

<listbox id="listModel" rows="10" mold="paging" pageSize="10"
    selectedItem="@{mainCtrl.selected}" fixedLayout="true"
    model="@{mainCtrl.model}">
    <listhead>
        <listheader
            label="${c:l('SYSADM.ManageImportedSubscribers.table.MSISDN')}"
            sort="auto" />
        <listheader
            label="${c:l('SYSADM.ManageImportedSubscribers.table.Date')}"
            sort="auto" />
        <listheader
            label="${c:l('SYSADM.ManageImportedSubscribers.table.CO_ID')}"
            sort="auto" />
        <listheader
            label="${c:l('SYSADM.ManageImportedSubscribers.table.Customer_ID')}"
            sort="auto" />
        <listheader label="Update ?" sort="auto" />
    </listhead>

    <listitem self="@{each=MANAGE_IMPORTED_SET_DATA}">
        <listcell>
            <label value="@{MANAGE_IMPORTED_SET_DATA.MSISDN}"></label>
            <textbox value="@{MANAGE_IMPORTED_SET_DATA.MSISDN}"
                visible="false" />
        </listcell>
        <listcell>
            <label value="@{MANAGE_IMPORTED_SET_DATA.IMPORT_ID}"></label>
            <textbox value="@{MANAGE_IMPORTED_SET_DATA.IMPORT_ID}"
                visible="false" />
        </listcell>
        <listcell>
            <label value="@{MANAGE_IMPORTED_SET_DATA.CO_ID}"></label>
            <textbox value="@{MANAGE_IMPORTED_SET_DATA.CO_ID}"
                visible="false" />
        </listcell>
        <listcell>
            <label value="@{MANAGE_IMPORTED_SET_DATA.CUSTOMER_ID}"></label>
            <textbox value="@{MANAGE_IMPORTED_SET_DATA.CUSTOMER_ID}"
                visible="false" />
        </listcell>
        <listcell>
            <button label="Update">
                <attribute name="onClick">
    Button update;
    Button delete;
    Button save;
    Button cancel;

    update = self;
    delete = self.getNextSibling();

    update.setVisible(false);
    delete.setVisible(false);

    Listitem listitem = self.getParent().getParent();
    int i = 0 ;                               
    while(i != 4){
        Listcell listcell = (Listcell)listitem.getChildren().get(i);
        ((Label)listcell.getChildren().get(0)).setVisible(false);
        ((Textbox)listcell.getChildren().get(1)).setVisible(true);
        i++;
    }

    self.getParent().appendChild(save=new Button("Save"));
    save.addEventListener("onClick",new EventListener() {
        public void onEvent(Event arg0) {
            alert("SAVE CLICKCED");
            }
    });                                                        

    self.getParent().appendChild(cancel = new Button("Cancel"));
    cancel.addEventListener("onClick",new EventListener() {
    public void onEvent(Event arg0) {
        Listitem listitem1 =  self.getParent().getParent();
        int i = 0 ;
        while(i != 4) {
            Listcell listcell = (Listcell)listitem1.getChildren().get(i);
            ((Label)listcell.getChildren().get(0)).setVisible(true);
            ((Textbox)listcell.getChildren().get(1)).setVisible(false);
            i++;
        }

        Listcell listcell = (Listcell)listitem1.getChildren().get(4);
        ((Button)listcell.getChildren().get(0)).setVisible(true);
        ((Button)listcell.getChildren().get(1)).setVisible(true);
        ((Button)listcell.getChildren().get(2)).detach();
        ((Button)listcell.getChildren().get(2)).detach();
        }
    });
                </attribute>
            </button>
            <button label="Delete" onClick="onDelete()"></button>
        </listcell>
        <listcell></listcell>
    </listitem>
</listbox>

I am trying to make editable listbox that gives user ability to update listitem or cancel it.But I can't get selected item for save it on another bean and then if user clicks cancel , show original record. This returns me null.

Listitem listitem =  self.getParent().getParent();
Listbox listbox = listitem.getListbox();
alert(listbox.getSelectedItem().getValue());

Also I am using zscript on .zul file for making this operation. here my listbox and update function

<listbox id="listModel" rows="10" mold="paging" pageSize="10"
    selectedItem="@{mainCtrl.selected}" fixedLayout="true"
    model="@{mainCtrl.model}">
    <listhead>
        <listheader
            label="${c:l('SYSADM.ManageImportedSubscribers.table.MSISDN')}"
            sort="auto" />
        <listheader
            label="${c:l('SYSADM.ManageImportedSubscribers.table.Date')}"
            sort="auto" />
        <listheader
            label="${c:l('SYSADM.ManageImportedSubscribers.table.CO_ID')}"
            sort="auto" />
        <listheader
            label="${c:l('SYSADM.ManageImportedSubscribers.table.Customer_ID')}"
            sort="auto" />
        <listheader label="Update ?" sort="auto" />
    </listhead>

    <listitem self="@{each=MANAGE_IMPORTED_SET_DATA}">
        <listcell>
            <label value="@{MANAGE_IMPORTED_SET_DATA.MSISDN}"></label>
            <textbox value="@{MANAGE_IMPORTED_SET_DATA.MSISDN}"
                visible="false" />
        </listcell>
        <listcell>
            <label value="@{MANAGE_IMPORTED_SET_DATA.IMPORT_ID}"></label>
            <textbox value="@{MANAGE_IMPORTED_SET_DATA.IMPORT_ID}"
                visible="false" />
        </listcell>
        <listcell>
            <label value="@{MANAGE_IMPORTED_SET_DATA.CO_ID}"></label>
            <textbox value="@{MANAGE_IMPORTED_SET_DATA.CO_ID}"
                visible="false" />
        </listcell>
        <listcell>
            <label value="@{MANAGE_IMPORTED_SET_DATA.CUSTOMER_ID}"></label>
            <textbox value="@{MANAGE_IMPORTED_SET_DATA.CUSTOMER_ID}"
                visible="false" />
        </listcell>
        <listcell>
            <button label="Update">
                <attribute name="onClick">
    Button update;
    Button delete;
    Button save;
    Button cancel;

    update = self;
    delete = self.getNextSibling();

    update.setVisible(false);
    delete.setVisible(false);

    Listitem listitem = self.getParent().getParent();
    int i = 0 ;                               
    while(i != 4){
        Listcell listcell = (Listcell)listitem.getChildren().get(i);
        ((Label)listcell.getChildren().get(0)).setVisible(false);
        ((Textbox)listcell.getChildren().get(1)).setVisible(true);
        i++;
    }

    self.getParent().appendChild(save=new Button("Save"));
    save.addEventListener("onClick",new EventListener() {
        public void onEvent(Event arg0) {
            alert("SAVE CLICKCED");
            }
    });                                                        

    self.getParent().appendChild(cancel = new Button("Cancel"));
    cancel.addEventListener("onClick",new EventListener() {
    public void onEvent(Event arg0) {
        Listitem listitem1 =  self.getParent().getParent();
        int i = 0 ;
        while(i != 4) {
            Listcell listcell = (Listcell)listitem1.getChildren().get(i);
            ((Label)listcell.getChildren().get(0)).setVisible(true);
            ((Textbox)listcell.getChildren().get(1)).setVisible(false);
            i++;
        }

        Listcell listcell = (Listcell)listitem1.getChildren().get(4);
        ((Button)listcell.getChildren().get(0)).setVisible(true);
        ((Button)listcell.getChildren().get(1)).setVisible(true);
        ((Button)listcell.getChildren().get(2)).detach();
        ((Button)listcell.getChildren().get(2)).detach();
        }
    });
                </attribute>
            </button>
            <button label="Delete" onClick="onDelete()"></button>
        </listcell>
        <listcell></listcell>
    </listitem>
</listbox>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

第七度阳光i 2024-10-27 19:28:04

数据绑定支持注释中的保存时间和加载时间概念。您可以在 zul 注释中指定“save-when: none”,这样 databinder 就不会自动将数据从 UI 保存到 bean 中。但是,您必须在事件侦听器中自行“保存”。

<listcell><label value="@{MANAGE_IMPORTED_SET_DATA.MSISDN}" ></label><textbox value="@{MANAGE_IMPORTED_SET_DATA.MSISDN, save-when='none'}" visible="false" /></listcell>
<listcell><label value="@{MANAGE_IMPORTED_SET_DATA.IMPORT_ID}"></label><textbox value="@{MANAGE_IMPORTED_SET_DATA.IMPORT_ID, save-when='none'}" visible="false" /></listcell>
<listcell><label value="@{MANAGE_IMPORTED_SET_DATA.CO_ID}" ></label><textbox value="@{MANAGE_IMPORTED_SET_DATA.CO_ID, save-when='none'}"  visible="false"/></listcell>
<listcell><label value="@{MANAGE_IMPORTED_SET_DATA.CUSTOMER_ID}"></label><textbox value="@{MANAGE_IMPORTED_SET_DATA.CUSTOMER_ID, save-when='none'}"  visible="false"  /> </listcell>

有关详细信息,您可以查看此JavaDoc(搜索“save-when”):

http://www.zkoss.org/javadoc/5.0/zk/org/zkoss/zkplus/databind/AnnotateDataBinder.html

The data binding support save-when and load-when concept in annotation. You can specify "save-when: none" in zul annotation so the databinder will not save data from UI into bean for you automatically. However, then you have to do the "save" by yourselves in your event listener.

<listcell><label value="@{MANAGE_IMPORTED_SET_DATA.MSISDN}" ></label><textbox value="@{MANAGE_IMPORTED_SET_DATA.MSISDN, save-when='none'}" visible="false" /></listcell>
<listcell><label value="@{MANAGE_IMPORTED_SET_DATA.IMPORT_ID}"></label><textbox value="@{MANAGE_IMPORTED_SET_DATA.IMPORT_ID, save-when='none'}" visible="false" /></listcell>
<listcell><label value="@{MANAGE_IMPORTED_SET_DATA.CO_ID}" ></label><textbox value="@{MANAGE_IMPORTED_SET_DATA.CO_ID, save-when='none'}"  visible="false"/></listcell>
<listcell><label value="@{MANAGE_IMPORTED_SET_DATA.CUSTOMER_ID}"></label><textbox value="@{MANAGE_IMPORTED_SET_DATA.CUSTOMER_ID, save-when='none'}"  visible="false"  /> </listcell>

For details, you can check this JavaDoc (search "save-when"):

http://www.zkoss.org/javadoc/5.0/zk/org/zkoss/zkplus/databind/AnnotateDataBinder.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文