Revision history [back]

click to hide/show revision 1
initial version

asked 2013-02-08 10:27:04 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India

http://emrpms.blogspot.in...

mvvm issue

Hi

  1. I have list page created MVVM Design.
  2. On Click of EDIT, i am passing the selected record to the modal window where user will be able to edit.
  3. The modal window has both Save and Exit button.
  4. When i modify the values in the modal window and close the window, i refreshed the list.
  5. But the problem is, when i change some thing and click the exit button, that time also the list is refreshed.

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();

}

}

mvvm issue

Hi

  1. I have list page created MVVM Design.
  2. On Click of EDIT, i am passing the selected record to the modal window where user will be able to edit.
  3. The modal window has both Save and Exit button.
  4. When i modify the values in the modal window and close the window, i refreshed the list.
  5. But the problem is, when i change some thing and click the exit button, that time also the list is refreshed.

How we can avoid this ?

 <?page title="Schools" contentType="text/html;charset=UTF-8"?>

<zk> <window id="winEditor" title="School Editor" border="normal" border="normal" height="350px" width="400px" closable="true" apply="org.zkoss.bind.BindComposer" viewmodel="@id('vm') 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"/> label="Save" onClick="@command('saveSchool')" image="/images/16_save.png" /> <toolbarbutton id="tbtnExit" label="Exit" onclick="@command('exitSchool')" image="/images/EXIT.GIF"/> label="Exit" onClick="@command('exitSchool')" image="/images/EXIT.GIF" /> </toolbar> <grid> <columns> <column width="100px"/> <column/> width="100px" /> <column /> </columns> <rows> <row> <label value="Code"/> value="Code" /> <textbox value="@bind(vm.selectedSchool.code)"/> value="@bind(vm.selectedSchool.code)" /> </row> <row> <label value="Name"/> value="Name" /> <textbox value="@bind(vm.selectedSchool.name)"/> value="@bind(vm.selectedSchool.name)" /> </row> <row> <label value="Address"/> <textbox value="@bind(vm.selectedSchool.address)"/> value="Address" /> <textbox value="@bind(vm.selectedSchool.address)" /> </row> </rows> </grid> </vlayout> </window> </zk>

</zk>

ChildSchoolsEditVM

 package org.com.demo;

import java.util.HashMap; import java.util.Map;

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;

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();

    }

}

}

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More