3

MVVM Notifychange works only along with @Command ?

asked 2013-07-05 14:40:13 +0800

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

Hi

Just a have quick question.

Code 1:

    @Command
public void onNextStep() {
    if (this.currentStep.equalsIgnoreCase("step1")) {
        doAfterStep1();
    }
}

@NotifyChange({ "canPrevious", "steps" })
public void doAfterStep1() {

    if (this.labOrder == null) {
        Messagebox.show("Please select Patient and then continue",
                "Select Patient", Messagebox.OK, Messagebox.INFORMATION);
        return;
    }
    Messagebox.show("asdsad");
    this.currentStep = "step2";
    this.canPrevious = true;
    this.steps = "Step : 2 Enter Patient Visit Information";
}

In the above, UI does not updated after doAfterStep1 is called. But when i change the code as follows

@Command
@NotifyChange({ "canPrevious", "steps" })
public void onNextStep() {
    if (this.currentStep.equalsIgnoreCase("step1")) {
        doAfterStep1();
    }
}


public void doAfterStep1() {

    if (this.labOrder == null) {
        Messagebox.show("Please select Patient and then continue",
                "Select Patient", Messagebox.OK, Messagebox.INFORMATION);
        return;
    }
    Messagebox.show("asdsad");
    this.currentStep = "step2";
    this.canPrevious = true;
    this.steps = "Step : 2 Enter Patient Visit Information";
}

Now it works. Why this behavior ?

delete flag offensive retag edit

6 Answers

Sort by ยป oldest newest most voted
8

answered 2013-07-08 07:43:29 +0800

hswain gravatar image hswain flag of India
1765 3 10
http://corejavaexample.bl...

updated 2013-07-29 06:32:36 +0800

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

as per my understanding @Command annotation use for identify method from zul page and @NotifyChange also notify when you call from zul page.

suppose you want notify doAfterStep1() method without @NotifyChange annotation

you can use

BindUtils.postNotifyChange(null, null, this, "*");
link publish delete flag offensive edit
4

answered 2013-07-09 08:49:56 +0800

ajaidka gravatar image ajaidka
196 4

updated 2013-07-09 09:53:00 +0800

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

@NotifyChange works on setters too

e.g in ZUL

<checkbox label="Time Sensitive Only"                       checked="@bind(vm.unfedPatientFilterTimeSensitiveOnly)" />

In java code (VM)

@NotifyChange("unfedPatients")
    public void setUnfedPatientFilterTimeSensitiveOnly(boolean unfedPatientFilterTimeSensitiveOnly) {
        this.unfedPatientFilterTimeSensitiveOnly = unfedPatientFilterTimeSensitiveOnly;
        initUnfedPatients();
    }

Thanks AJaidka Paxcel Technologies

link publish delete flag offensive edit

Comments

This one is good to know! Thanks AJaidka Paxcel Technologies and sjoshi.

nsharma ( 2013-07-09 11:44:20 +0800 )edit
2

answered 2014-01-24 19:43:28 +0800

sitansu gravatar image sitansu
2254 13
http://java91.blogspot.in...

updated 2014-01-24 19:44:41 +0800

@Command :ViewModel's Command is like an event handler, we can bind an event to a Command. The binding between events and a command is what we call "Event-Command Binding". Before establish this binding, we have to declare a Command with its name in a ViewModel.

@NotifyChange("*"):To notify binder one or more properties change.

link publish delete flag offensive edit
1

answered 2013-07-05 15:01:24 +0800

davout gravatar image davout
1429 2 18

My guess is that @Command and @NotifyChange are joined at the hip - they have to be declared against the same class method.

link publish delete flag offensive edit
1

answered 2013-07-05 22:15:14 +0800

rickcr gravatar image rickcr
704 7

Yes. I've posted about this before. I really wish you could create "notify changes" on other methods that your command calls, but alas that is not the case. I assume the devs have some good reason for this?

It actually gets even more frustrating Senthilchettyin when you have a base class VM method that has a command and the base class command now delegates a call down to one of its implementing class methods. I didn't want to have constantly update the base class method command with every possible notify change that a subclass could use that happens to implement this Base VM (really breaks the OO paradigm there, especially if you're building a library.)

I wrote about the solution here http://www.learntechnology.net/2013/04/01/notify-change-from-base.html as was really provided to me Matze2

link publish delete flag offensive edit

Comments

rickcr, Can you please give or write article in your site for implementing base class VM with command methods such as Add, Edit , delete and view ?

Senthilchettyin ( 2013-07-21 13:03:22 +0800 )edit
1

answered 2013-07-06 03:57:15 +0800

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

Hi rickcr

Thank you very much. I learned some new stuff today :)

senthil

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2013-07-05 14:40:13 +0800

Seen: 245 times

Last updated: Jan 24 '14

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