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