JAVA:ZK框架如何将两个bean设置为列表框?
我正在尝试制作可编辑的列表框,使用户能够更新列表项或取消它。但是我无法获取选定的项目以将其保存在另一个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
数据绑定支持注释中的保存时间和加载时间概念。您可以在 zul 注释中指定“save-when: none”,这样 databinder 就不会自动将数据从 UI 保存到 bean 中。但是,您必须在事件侦听器中自行“保存”。
有关详细信息,您可以查看此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.
For details, you can check this JavaDoc (search "save-when"):
http://www.zkoss.org/javadoc/5.0/zk/org/zkoss/zkplus/databind/AnnotateDataBinder.html