-1

mvvm issue [closed]

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

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

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

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

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

    }

}
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

Comments

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
2

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

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

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

link publish delete flag offensive edit
0

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

Follow
2 followers

RSS

Stats

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