mvvm issue [closed]

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

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8

updated 2013-02-08 10:39:00 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8


  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"?>
    <window id="winEditor" title="School Editor" border="normal"
        height="350px" width="400px" closable="true"
        viewModel="@id('vm') @init('org.com.demo.ChildSchoolsEditVM')">
                <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" />
                    <column width="100px" />
                    <column />
                        <label value="Code" />
                        <textbox value="@bind(vm.selectedSchool.code)" />
                        <label value="Name" />
                        <textbox value="@bind(vm.selectedSchool.name)" />
                        <label value="Address" />
                            value="@bind(vm.selectedSchool.address)" />


 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;
    private Window winEditor;

    public School getSelectedSchool() {
        return selectedSchool;

    public void setSelectedSchool(School selectedSchool) {
        this.selectedSchool = selectedSchool;

    public void initSetup(@ContextParam(ContextType.VIEW) Component view,
            @ExecutionArgParam("SELECTED_SCHOOL") School selectedSchool) {
        Selectors.wireComponents(view, this, false);
        this.selectedSchool = selectedSchool;


    public void exitSchool() {

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public void saveSchool() {
        Map args = new HashMap();
        args.put("modifiedSchool", this.selectedSchool);
        BindUtils.postGlobalCommand(null, null, "onSchoolSaved", args);


delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by Senthilchettyin
close date 2013-02-09 06:46:54


Thats the right answer. thank you.

Senthilchettyin ( 2013-02-09 06:46:40 +0800 )edit

Please accept right answer

sjoshi ( 2013-02-11 08:21:26 +0800 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2013-02-08 10:49:19 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8

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

link publish delete flag offensive edit

answered 2013-02-08 14:27:00 +0800

yaminglin1977 gravatar image yaminglin1977
36 2

replace @bind(vm.selectedSchool.code) with @load(vm.selectedSchool.code) @save(vm.selectedSchool.code,before='saveSchool')

link publish delete flag offensive edit

Question tools




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

Seen: 35 times

Last updated: Feb 09 '13

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