-
FEATURED COMPONENTS
First time here? Check out the FAQ!
1 | initial version | |
Hi, I have a main windows with a list box to show a list of records. When a row is selected, another modal popup window for editing the selected record will be triggered by right click the context menu item. I have databinding in the main window and I expect all changes made in the modal popup window will be reflected back to the main window. Unfortunately, it is not the case. Can I use any databinding concepts to tackle this problem ?
Appreciate anyone could give me a hand and resolve the subject problem. Million Thanks. / Jonathan
Main Window
<?page title="School" contentType="text/html;charset=UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
<zk>
<window id="schoolctlview" title="School" border="normal"
apply="model.SchoolViewCtl">
<listbox id="lbSchool" mold="paging" pageSize="10"
selectedItem="@{selected}" context="GridMenu">
<auxhead sclass="category-center">
<auxheader colspan="1">
<image src="/img/funnel.png" />
<textbox id="filter21" />
</auxheader>
<auxheader colspan="1">
<image src="/img/funnel.png" />
<textbox id="filter22" />
</auxheader>
<auxheader colspan="1">
<image src="/img/funnel.png" />
<textbox id="filter23" />
</auxheader>
<auxheader colspan="1">
<image src="/img/funnel.png" />
<textbox id="filter24" />
</auxheader>
<auxheader colspan="1">
<image src="/img/funnel.png" />
<textbox id="filter25" />
</auxheader>
</auxhead>
<listhead>
<listheader label="School Code" />
<listheader label="School Name" />
<listheader label="Tel" />
<listheader label="Fax" />
<listheader label="Email" />
</listhead>
</listbox>
<menupopup id="GridMenu">
<menuitem id="mitemView" label="View" />
</menupopup>
</window>
</zk>
Modal Popup Window
<?page id="pageSchool"title="School" contentType="text/html;charset=UTF-8"?>
<window id="wSchool" title="School" border="normal" mode="modal">
<zscript><![CDATA[
import model.School;
School sch = (School)execution.getArg().get("data");
]]></zscript>
<label value="Name:" />
<textbox id="nameTb" value="@{sch.school_name}"/>
<button label="OK" xmlns:w="http://www.zkoss.org/2005/zk/client" w:onClick="this.$f('wSchool').fire('onClose');"/>
</window>
Control
package model;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.SuspendNotAllowedException;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zkplus.databind.AnnotateDataBinder;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;
import org.zkoss.zul.Menuitem;
import org.zkoss.zul.Window;
public class SchoolViewCtl extends GenericForwardComposer {
private Listbox lbSchool;
private Menuitem mitemView;
private AnnotateDataBinder binder;
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
List allSchools = new SchoolDAO().findAll();
ListModelList model = new ListModelList(allSchools);
model.addSelection(allSchools.get(0));
lbSchool.setModel(model);
lbSchool.setItemRenderer(new ListitemRenderer() {
public void render(Listitem listItem, Object data) throws Exception {
final School sch = (School) data;
listItem.setValue(sch);
new Listcell(sch.getSchool_code()).setParent(listItem);
new Listcell(sch.getSchool_name()).setParent(listItem);
new Listcell(sch.getTel()).setParent(listItem);
new Listcell(sch.getFax()).setParent(listItem);
new Listcell(sch.getEmail()).setParent(listItem);
}
});
}
public void onClick$mitemView() {
Window wSchool = new Window();
Map data = new HashMap();
data.put("data", (School)lbSchool.getSelectedItem().getValue());
wSchool = (Window)Executions.getCurrent().createComponents("school.zul", self, data);
binder = new AnnotateDataBinder(wSchool);
binder.loadAll();
}
}