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

时间:2011-03-07 12:54:33

标签: listbox selecteditem zk

我正在尝试制作可编辑的列表框,使用户能够更新listitem或取消它。但是我无法获取所选项目以将其保存在另一个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>

1 个答案:

答案 0 :(得分:0)

数据绑定支持注释中的save-when和load-when概念。您可以在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