javamultithreadingzkzk-grid

NotifyChange part of a model in ZK


In my zul I have a Grid and I am using two named templates for it. I have used a model from my VM in my zul which I am using in the Grid template. Now I am modifying the model in a thread in the VM and upon the completion of thread, I am postNOtifyingChange from the VM. The problem is I want to modify only a part of the model in the zul(which has been modified by the thread). Because if the other part is also refreshed in the view, the change made by the user will be lost when postNotifyChange fires. The zul code is:

 <window apply="org.zkoss.bind.BindComposer"
    viewModel="@id('vm') @init('The View Model')"
    validationMessages="@id('vmsgs')">
    <grid id="componentgrid" height="900px" model="@load(vm.tablefields) @template((vm.displayEdit) ? 'editable' : 'noneditable')">
        <columns>
            <column>Attribute</column>
            <column>NOSS</column>
            <column>Beacon</column>
        </columns>
        <rows>
            <template name="noneditable">
                <row>
                    <label value="${each.attributename}"></label>
                    <label value="${each.attributevalue}"></label>
                    <label value="${each.beaconValue}"></label>


                </row>
            </template>

            <template name="editable">
                <row>

                    <label value="${each.gui_label}"></label>
                    <zk choose="">
                        <zk when="${each.enum_map ne null}">
                            <combobox id="${each.name}" value="${each.value}" width="150px">
                                <comboitem label="${each.value}" value="${each.key}"
                                    forEach="${each.enum_map}" />
                            </combobox>
                        </zk>
                        <zk when="${each.date == true}">
                            <datebox id="${each.name}" cols="12" format="short "
                                value="${each.datevalue}" />
                        </zk>
                        <zk>
                            <textbox id="${each.name}" value="${each.value}" />
                        </zk>
                    </zk>
                    <label value="${each.beaconValue}"></label>

                </row>


            </template>

        </rows>
    </grid>
    </window>

So here I just want to NotifyChange on "${each.beaconValue}" part.In the ViewMOdel, I am doing BindUtils.postNotifyChange(null, null,NNComponentDetailViewModel.this, "tablefields"); to notifychange in this model. Is this approach correct ? How can this be achieved that only part of the model will be changed? Or is there any other approach as I think ZK allows only one model in a Grid. Please suggest as this seems to be blocked because of ZK framework limitation.


Solution

  • If you want a part of the model changed you have to say that the object is changed.

    Example :

    BindUtils.postNotifyChange(null, null, oneObjectOfYourModel, "*"); 
    

    or if you only want to change the "beaconValue" :

    BindUtils.postNotifyChange(null, null, oneObjectOfYourModel, "beaconValue");
    

    Of course when you adjust almost all the objects you have to call the notifychanged more then once, but this is the solution for your problem.