0

MVVM : @NotifyChange

asked 2012-10-30 11:28:05 +0800

mkommer gravatar image mkommer
111

updated 2012-10-30 11:28:45 +0800

i would like if it is possible to have some chain of notifychange.

For example,

a setter is called and it has a @NotifyChange for some attributes, but in the setter method, others methods are called and have their own @NotifyChange.

It seems the children are not called. Is there a way to do it ?

Thank you.

@NotifyChange({"myVar"})
public void setMyVar(String myVar) {
      this.myVar = myVar;
      if myVar.equals("test") {
            loadInterface();
      }
}

// Seems NotifyChange not be called
@NotifyChange({"tata", "titi", "tutu"})
public void loadInterface() {
    tata = "ok";
    titi = "nok";
    tutu = "NA";
}

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2012-10-30 12:33:25 +0800

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

I think for single Variable NotifyChange u have to use like this...

@NotifyChange("myVariable")

if You want to notify every variable declare in class you can use.

@NotifyChange("*")

link publish delete flag offensive edit

answered 2012-10-30 13:03:51 +0800

Steva77 gravatar image Steva77 flag of Italy
1014 3
http://www.research.softe...

Mmmmh... I made something like e.g.:

	@NotifyChange({"offsetDate", "measures"})
	@Command("setOffsetDate")
	public void setOffsetDate (@BindingParam("offsetDate") Date d){
		this.offsetDate = d;
		this.measures = this.readLatestMeasures();		
	}	

As you can see I invoke this.readLatestMeasure(), but the "notified" variable is in the caller method.
Is myVar correctly retrieved without binding?

link publish delete flag offensive edit

answered 2012-10-30 13:38:27 +0800

mkommer gravatar image mkommer
111

So if i want to notify 10 attributes, i have to add it all to the notifycommand.....cause * is perhaps excessive

link publish delete flag offensive edit

answered 2012-10-30 13:41:59 +0800

Steva77 gravatar image Steva77 flag of Italy
1014 3
http://www.research.softe...

It worked for me... but the approach is a bit different, could be nice to understand if you encountered a limitation in the notification chain or not.

link publish delete flag offensive edit

answered 2012-10-30 14:17:13 +0800

rickcr gravatar image rickcr
704 7

I've noticed the same thing when trying to call another method in your ViewModel. It would be nice if you only had to annotate the method closest to the data.. but that's not the case... you need to use notify on the method that is 'first called from your view.'

For example I wish you could do...

@Command
public void update() { 
  //..do stuff
  updatePage();
}

@Command
public void create() { 
  //..do stuff
  updatePage();
}

@NotifyChange("stuff") 
public void updatePage() {
   stuff = service.getStuff();
   //..doStuff
}

The above won't work though. You need to have the @Notify("stuff") on both the update and the create methods. If you have a lot to notify that's sort of annoying. Note also, the update or create might not even be setting "stuff" - it's done another method.. but you have to declare on the initial command called.

On a related note, I'd also like to be able to use a single command as both a regular @Command and a @GlobalCommand but I can't figure out how to to do it? So I end up with two method have have identical Notifies on them. Annoying when you have a lot of properties and dont' want to use *


@NotifyChange("stuff")
@Command
public void doStuff() { }

//all this does is proxy to one above, be nice if I could make the one 
//above act as both a regular view command and a global?
@NotifyChange("stuff")
@GlobalCommand
public void doStuffGlobal() {
    doStuff();
}

link publish delete flag offensive edit

answered 2012-10-30 16:49:02 +0800

mkommer gravatar image mkommer
111

could the solution be the "dependson" annotation (?)

link publish delete flag offensive edit

answered 2012-10-30 16:54:00 +0800

Steva77 gravatar image Steva77 flag of Italy
1014 3
http://www.research.softe...

updated 2012-10-30 16:56:57 +0800

Mmmhhh... interesting, I have still not evaluated the whole ZK 6.X stuff...
http://books.zkoss.org/wiki/ZK%20Developer's%20Reference/MVVM/Syntax/ViewModel/@DependsOn deserves attention indeed, although I still do not clearly see the solution... thanks!

And for @Command and @GlobalCommand I think this is the only way so far... at least, it (annoyingly ;) works...

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2012-10-30 11:28:05 +0800

Seen: 223 times

Last updated: Oct 30 '12

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