-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello,
I'm struggling to get NotifyChange to work.
What I want to do is to notify the parent view of some changes and then show those changed values in another viewmodel which is a child of the parentview.
-------------------------------------- | parent view | | | | -------------- -------------- | | | child 1 | | child 2 | | | -------------- -------------- | --------------------------------------
I get neither @NotifyChange nor BindUtils.postNotifyChange to work.
My example implementation looks like this:
ParentView:
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver">
<?page title="sandbox" contentType="text/html;charset=UTF-8"?>
<?component name="sandboxinclude" macro-uri="sandboxinclude.zul" inline="true"?>
<?component name="child1" macro-uri="child1.zul" inline="true"?>
<?component name="child2" macro-uri="child2.zul" inline="true"?>
<zk>
<window border="normal" title="macro with reference"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('sandBoxVm')
@init('com.businesskeeper.voiceintake.viadmin.viewmodel.Sandbox')">
<child1/>
<child2/>
</window>
</zk>
Child 1 (with a lot of different approaches)
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<zk>
<div apply="org.zkoss.bind.BindComposer"
viewModel="@id('child1Vm')
@init('com.businesskeeper.voiceintake.viadmin.viewmodel.Child1')">
<button
label="(@NotifyChange(*))"
onClick="@command('changeValue00', toChange=sandBoxVm.toChange )"/>
<button
label="(@NotifyChange(toChange))"
onClick="@command('changeValue0', toChange=sandBoxVm.toChange )"/>
<button
label="(null, null, this, toChange)"
onClick="@command('changeValue1', toChange=sandBoxVm.toChange )"/>
<button
label="(null, null, this, *)"
onClick="@command('changeValue2', toChange=sandBoxVm.toChange )"/>
<button
label="(null, null, Child1.class, *)"
onClick="@command('changeValue3', toChange=sandBoxVm.toChange )"/>
<button
label="(null, null, Child1.class, toChange)"
onClick="@command('changeValue4', toChange=sandBoxVm.toChange )"/>
<button
label="(null, null, Child1.this, *)"
onClick="@command('changeValue3_2', toChange=sandBoxVm.toChange )"/>
<button
label="(null, null, Child1.this, toChange)"
onClick="@command('changeValue4_2', toChange=sandBoxVm.toChange )"/>
<button
label="(null, null, Sandbox.class, *)"
onClick="@command('changeValue5', toChange=sandBoxVm.toChange )"/>
<button
label="(null, null, Sandbox.class, toChange)"
onClick="@command('changeValue6', toChange=sandBoxVm.toChange )"/>
<button
label="(null, null, view.getParent(), toChange)"
onClick="@command('changeValue7', toChange=sandBoxVm.toChange )"/>
<button
label="(null, null, view.getParent(), *)"
onClick="@command('changeValue8', toChange=sandBoxVm.toChange )"/>
</div>
</zk>
Child 2 (shows only the value
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<zk>
<div apply="org.zkoss.bind.BindComposer"
viewModel="@id('child2Vm')
@init('com.businesskeeper.voiceintake.viadmin.viewmodel.Child2')">
<label value="@bind(sandBoxVm.toChange)"/>
</div>
</zk>
Java classes:
Sandbox
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* sandbox, try and play with stuff
*/
@Component("Sandbox")
@Scope("prototype")
public class Sandbox {
private String toChange = "initial value";
public String getToChange() {
return toChange;
}
public void setToChange(String toChange) {
this.toChange = toChange;
}
}
Child 1
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.stereotype.Component;
import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.*;
@Component("Child1")
public class Child1 {
@NotifyChange("*")
@Command
public void changeValue00(@BindingParam("toChange") String toChange){
toChange = "changed from Child1" + " " + RandomStringUtils.randomAlphabetic(8);
}
@NotifyChange("toChange")
@Command
public void changeValue0(@BindingParam("toChange") String toChange){
toChange = "changed from Child1" + " " + RandomStringUtils.randomAlphabetic(8);
}
@Command
public void changeValue1(@BindingParam("toChange") String toChange){
toChange = "changed from Child1" + " " + RandomStringUtils.randomAlphabetic(8);
BindUtils.postNotifyChange(null, null, this, "toChange");
}
@Command
public void changeValue2(@BindingParam("toChange") String toChange){
toChange = "changed from Child1" + " " + RandomStringUtils.randomAlphabetic(8);
BindUtils.postNotifyChange(null, null, this, "*");
}
@Command
public void changeValue3(@BindingParam("toChange") String toChange){
toChange = "changed from Child1" + " " + RandomStringUtils.randomAlphabetic(8);
BindUtils.postNotifyChange(null, null, Child1.class, "*");
}
@Command
public void changeValue4(@BindingParam("toChange") String toChange){
toChange = "changed from Child1" + " " + RandomStringUtils.randomAlphabetic(8);
BindUtils.postNotifyChange(null, null, Child1.class, "toChange");
}
@Command
public void changeValue3_2(@BindingParam("toChange") String toChange){
toChange = "changed from Child1" + " " + RandomStringUtils.randomAlphabetic(8);
BindUtils.postNotifyChange(null, null, Child1.this, "*");
}
@Command
public void changeValue4_2(@BindingParam("toChange") String toChange){
toChange = "changed from Child1" + " " + RandomStringUtils.randomAlphabetic(8);
BindUtils.postNotifyChange(null, null, Child1.this, "toChange");
}
@Command
public void changeValue5(@BindingParam("toChange") String toChange){
toChange = "changed from Child1" + " " + RandomStringUtils.randomAlphabetic(8);
BindUtils.postNotifyChange(null, null, Sandbox.class, "*");
}
@Command
public void changeValue6(@BindingParam("toChange") String toChange){
toChange = "changed from Child1" + " " + RandomStringUtils.randomAlphabetic(8);
BindUtils.postNotifyChange(null, null, Sandbox.class, "toChange");
}
@Command
public void changeValue7(@ContextParam(ContextType.VIEW) org.zkoss.zk.ui.Component view,
@BindingParam("toChange") String toChange){
toChange = "changed from Child1" + " " + RandomStringUtils.randomAlphabetic(8);
BindUtils.postNotifyChange(null, null, view.getParent(), "toChange");
}
@Command
public void changeValue8(@ContextParam(ContextType.VIEW) org.zkoss.zk.ui.Component view,
@BindingParam("toChange") String toChange){
toChange = "changed from Child1" + " " + RandomStringUtils.randomAlphabetic(8);
BindUtils.postNotifyChange(null, null, view.getParent(), "*");
}
}
Child 2 is an empty class
Is my approach wrong and this use case is not possible or can you tell me what is wrong with my implementation?
Any help would be deeply appreciated.
Thank you very much in advance.
Robert Schröder
Asked: 2015-12-15 09:39:59 +0800
Seen: 31 times
Last updated: Dec 15 '15
duplicated : http://forum.zkoss.org/question/99681/notify-parentviewmodel-with-notifychange-or-bindutils-from-childview-and-display-in-another-childview/
chillworld ( 2015-12-15 09:55:09 +0800 )edit