-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi
How we can avoid this ?
<?page title="Schools" contentType="text/html;charset=UTF-8"?>
<zk>
<window id="winEditor" title="School Editor" border="normal"
height="350px" width="400px" closable="true"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('org.com.demo.ChildSchoolsEditVM')">
<vlayout>
<toolbar>
<toolbarbutton id="tbtnSave" label="Save"
onClick="@command('saveSchool')" image="/images/16_save.png" />
<toolbarbutton id="tbtnExit" label="Exit"
onClick="@command('exitSchool')" image="/images/EXIT.GIF" />
</toolbar>
<grid>
<columns>
<column width="100px" />
<column />
</columns>
<rows>
<row>
<label value="Code" />
<textbox value="@bind(vm.selectedSchool.code)" />
</row>
<row>
<label value="Name" />
<textbox value="@bind(vm.selectedSchool.name)" />
</row>
<row>
<label value="Address" />
<textbox
value="@bind(vm.selectedSchool.address)" />
</row>
</rows>
</grid>
</vlayout>
</window>
</zk>
ChildSchoolsEditVM
package org.com.demo;
import java.util.HashMap;
import java.util.Map;
import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.bind.annotation.ExecutionArgParam;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.Selectors;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Window;
public class ChildSchoolsEditVM {
private School selectedSchool;
@Wire("#winEditor")
private Window winEditor;
public School getSelectedSchool() {
return selectedSchool;
}
public void setSelectedSchool(School selectedSchool) {
this.selectedSchool = selectedSchool;
}
@AfterCompose
public void initSetup(@ContextParam(ContextType.VIEW) Component view,
@ExecutionArgParam("SELECTED_SCHOOL") School selectedSchool) {
Selectors.wireComponents(view, this, false);
this.selectedSchool = selectedSchool;
}
@Command
public void exitSchool() {
winEditor.detach();
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Command
public void saveSchool() {
Map args = new HashMap();
args.put("modifiedSchool", this.selectedSchool);
BindUtils.postGlobalCommand(null, null, "onSchoolSaved", args);
winEditor.detach();
}
}
One thing i can suggest you that rather than using PostGlobalCommand you can use below code..
Binder bind = (Binder) view.getParent().getAttribute("binder");
if (bind == null)
return;
bind.postCommand("doColumnReordering", params);
It will call doColumnReordering method of parentView Model
And i thing rather than passing selected object directly you can pass a new coy of this object because you bind the object and may be you also bind the model object in listbox so if any change will done in object variable it will automatically reflect in Listbox as well so in your childModel window rather than passing elected object directly pass a copy of this object
replace @bind(vm.selectedSchool.code) with @load(vm.selectedSchool.code) @save(vm.selectedSchool.code,before='saveSchool')
Asked: 2013-02-08 10:27:04 +0800
Seen: 35 times
Last updated: Feb 09 '13
Databinding and auto-complete on combobox
Composite component and bind in ZK 6
How to detach / reattach MVVM windows?
Is there a way to resolve view model properties as input to client side javascripts?
How can I synchronize data in a ListBox in MVVM ? [closed]
MVVM Validator: class not found ? [closed]
How to Call Child ViewModel Method from Parent Window? [closed]
[Solved]Aplikasi Hibernate Spring [closed]
zk mvvm > what's the best component to make LOV (list of value) of a master data [closed]
Thats the right answer. thank you.
Senthilchettyin ( 2013-02-09 06:46:40 +0800 )editPlease accept right answer
sjoshi ( 2013-02-11 08:21:26 +0800 )edit