0

Notify change parentview from childview and display in another childview [closed]

asked 2015-12-15 09:39:59 +0800

R0bse gravatar image R0bse
1

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

delete flag offensive retag edit

The question has been closed for the following reason "duplicate question" by chillworld
close date 2015-12-15 09:54:59

Comments

Question tools

Follow

RSS

Stats

Asked: 2015-12-15 09:39:59 +0800

Seen: 31 times

Last updated: Dec 15 '15

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