0

Notifychanges not working in @listen event

asked 2014-09-22 14:46:47 +0800

sathishk gravatar image sathishk
17 5

updated 2014-09-22 15:04:51 +0800

chillworld gravatar image chillworld flag of Belgium
5322 4 9
https://github.com/chillw...

Hai Sir,I am new at Zk frame work, notifychanges working fine in @command,but not working in @listen event. how can i rectify this issue, please help me.

i need to display grid with records getting from below BillingPlanServiceImpl.

@NotifyChange("billingPlansList2")
@Listen("onClick = #bplanlink")
public void billingPlan() {
    tabbox.setSelectedPanel(bplanpanel);    
    tabcontact.setVisible(false);
    tabwrite.setVisible(false);
    tabmyprofile.setVisible(false);
    tabkowledge.setVisible(false);
    tabfaq.setVisible(false);
    tabbplan.setVisible(true);
    billingPlansList2 = new BillingPlanServiceImpl().getBillinPlanList("");

    for(BillingPlan bplan : billingPlansList2) {
        billplan = new BillingPlan();
        System.out.println(":bplan.getBillingdate():-"+bplan.getBillingdate());        
        billplan.setBillingdate(bplan.getBillingdate());
    }

    BindUtils.postGlobalCommand(null, null, "refresh", null);
    BindUtils.postNotifyChange(null, null, this, "*");

}

@GlobalCommand
@NotifyChange("billingPlansList2")
public void refresh(){
    System.out.println("Enter to refresh global command:-");
}
delete flag offensive retag edit

5 Answers

Sort by ยป oldest newest most voted
1

answered 2014-09-22 15:03:06 +0800

chillworld gravatar image chillworld flag of Belgium
5322 4 9
https://github.com/chillw...

Hi sathishk,

First of all, @NotifyChange only works for comands and setters, see documentation.

Secondly, If you use @Listen => MVC and @NotifyChange => MVVM you are doing something wrong.

If you need to do a notifychange outside a command or setter you can always use BindUtils:

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

In mine eye's you have to change the @Listen to a @Command and everything will work.

in zul this shall look like :

<button id="bplanlink" onClick="@command('billingPlan')"/>

Greetz chill.

link publish delete flag offensive edit

Comments

Thanks you for reply..

sathishk ( 2014-09-23 07:39:37 +0800 )edit

in @Listen event how can i refresh normal grid?

sathishk ( 2014-09-23 11:09:47 +0800 )edit

because i am using java code with @listen events,Please suggest me,how can i rectify this issue

sathishk ( 2014-09-23 11:10:55 +0800 )edit

no problem, but what do you use, MVC or MVVM? otherwise post zul and controller so I can suggest a refactoring

chillworld ( 2014-09-23 11:22:31 +0800 )edit

totally agree, better not mix the MVC and MVVM pattern, unless you know exactly what you are doing

cor3000 ( 2014-09-25 08:22:24 +0800 )edit
0

answered 2014-09-23 11:50:04 +0800

sathishk gravatar image sathishk
17 5

updated 2014-09-23 12:12:56 +0800

This is my zul file......

<zk xmlns:h="native">
    <window id="win" border="none" apply="org.novelerp.controller.DashboardUIController" xmlns:d="http://www.zkoss.org/2005/zk/client/attribute">
        <div class="dashboard_links" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('org.novelerp.controller.DashboardUIController')">
            <h:ul>
                <h:li class="gu no-border" if="${sessionScope.isCRCAdmin}">
                    <a id="bplanlink">Billing Plan</a>
                </h:li>
            </h:ul>
        </div>
        <tabbox mold="accordion" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('org.novelerp.controller.DashboardUIController')">
            <tabs>
                <tab sclass="gu" id="tabbplan" style="font-size: 13px;" if="${sessionScope.isCustomer}" visible="false">Billing Plan</tab>
            </tabs>
            <tabpanels>
                <tabpanel id="bplanpanel" if="${sessionScope.isCustomer}" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('org.novelerp.controller.DashboardUIController')">
                    <grid model="@bind(vm.billingPlansList2)" >
                        <columns sizable="true">
                            <column label="Billing Date"></column>
                            <column label="Date Description"></column>
                            <column label="MileStone Relavance"></column>
                            <column label="Block"></column>
                            <column label="Billing Status"></column>
                        </columns>
                        <template name="model">
                            <row>
                                <label value="@bind(each.billingdate)"></label>
                                <label value="@bind(each.datedescription)"></label>
                                <label value="@bind(each.milestonerelavance)"></label>
                                <label value="@bind(each.billingblock)"></label>
                                <label value="@bind(each.billingstatus)"></label>
                            </row>
                        </template>
                    </grid>
                </tabpanel>
            </tabpanels>

        </tabbox>
    </window>
</zk>

My Controller

@NotifyChange("billingPlansList2")
@Listen("onClick = #bplanlink")
public void billingPlan() {
    tabbox.setSelectedPanel(bplanpanel);
    tabbplan.setVisible(true);
    billingPlansList2 = new BillingPlanServiceImpl().getBillinPlanList("");

    for (BillingPlan bplan : billingPlansList2) {
        billplan = new BillingPlan();
        System.out.println(":bplan.getBillingdate():-" + bplan.getBillingdate());
        billplan.setBillingdate(bplan.getBillingdate());
    }

    BindUtils.postGlobalCommand(null, null, "refresh", null);
    BindUtils.postNotifyChange(null, null, this, "*");
}

@GlobalCommand
@NotifyChange("billingPlansList2")
public void refresh() {
    System.out.println("Enter to refresh global command:-");
}

Please help me.....

link publish delete flag offensive edit

Comments

can you do the whole controller? I can't see where tabfaq comes from.

chillworld ( 2014-09-23 12:07:08 +0800 )edit

tabfaq removed from controller

sathishk ( 2014-09-23 12:14:04 +0800 )edit

Please help me

sathishk ( 2014-09-23 12:47:32 +0800 )edit
0

answered 2014-09-23 13:11:13 +0800

chillworld gravatar image chillworld flag of Belgium
5322 4 9
https://github.com/chillw...

updated 2014-09-23 14:56:07 +0800

ZUL :

<zk xmlns:h="native">
    <window id="win" border="none" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('org.novelerp.controller.DashboardUIController')" xmlns:d="http://www.zkoss.org/2005/zk/client/attribute">
        <div class="dashboard_links">
            <h:ul>
                <h:li class="gu no-border" if="${sessionScope.isCRCAdmin}">
                    <a id="bplanlink" onClick="@command('bplanlink', selected = bplanpanel)">Billing Plan</a>
                </h:li>
            </h:ul>
        </div>
        <tabbox mold="accordion" selectedPanel="@bind(vm.selectedPanel)">
            <tabs>
                <tab sclass="gu" id="tabbplan" style="font-size: 13px;" if="${sessionScope.isCustomer}" visible="@load(vm.tabbplanVisible)">Billing Plan</tab>
            </tabs>
            <tabpanels>
                <tabpanel id="bplanpanel" if="${sessionScope.isCustomer}">
                    <grid model="@bind(vm.billingPlansList2)" >
                        <columns sizable="true">
                            <column label="Billing Date"></column>
                            <column label="Date Description"></column>
                            <column label="MileStone Relavance"></column>
                            <column label="Block"></column>
                            <column label="Billing Status"></column>
                        </columns>
                        <template name="model">
                            <row>
                                <label value="@bind(each.billingdate)"></label>
                                <label value="@bind(each.datedescription)"></label>
                                <label value="@bind(each.milestonerelavance)"></label>
                                <label value="@bind(each.billingblock)"></label>
                                <label value="@bind(each.billingstatus)"></label>
                            </row>
                        </template>
                    </grid>
                </tabpanel>
            </tabpanels>

        </tabbox>
    </window>
</zk>

JAVA

See that class don't extend any class. remove also all the @wire.

public class DashboardUIController {

    private Boolean tabbplanVisible = Boolean.FALSE;
    private Tabpanel selectedPanel;

    public Boolean getTabbplanVisible () {
        return tabbplanVisible;
    }

    public void setTabbplanVisible(Boolean tabbplanVisible) {
        this.tabbplanVisible = tabbplanVisible;
    }

    public Tabpanel getSelectedPanel () {
        return selectedPanel;
    }

    public void setSelectedPanel (Tabpanel selectedPanel) {
        this.selectedPanel = selectedPanel;
    }


    @NotifyChange({"billingPlansList2","selectedPanel","tabbplanVisible"})
    public void billingPlan(@BindingParam("selected") Tabpanel bplanpanel) {
        setSelectedPanel(bplanpanel);
        setTabbplanVisible(Boolean.TRUE);
        billingPlansList2 = new BillingPlanServiceImpl().getBillinPlanList("");

        for (BillingPlan bplan : billingPlansList2) {
            billplan = new BillingPlan();
            System.out.println(":bplan.getBillingdate():-" + bplan.getBillingdate());
            billplan.setBillingdate(bplan.getBillingdate());
        }
    }

}

Try this. Didn't test it(wrote it in notepad++) but it shall be close to what you want.

Greetz chill.

link publish delete flag offensive edit

Comments

without @command can i do @listen event for refresh a grid?

sathishk ( 2014-09-24 06:24:40 +0800 )edit

removed tabs and put it on tabbox tag,it's shows error like selectedpanel not a property of tabbox

sathishk ( 2014-09-24 07:02:48 +0800 )edit

what version? this is already there from zk 6.0.0 for sure : http://www.zkoss.org/javadoc/6.0.0/zk/org/zkoss/zul/Tabbox.html (see good if caps are correct, selectedpanel != selectedPanel)

chillworld ( 2014-09-24 08:04:27 +0800 )edit

I am using zk 6.5.2,i am getting error like nested exception is org.zkoss.zk.ui.UiException: Error writing 'selectedPanel' on type org.zkoss.zul.Tabbox at dashboard.zul

sathishk ( 2014-09-24 09:31:51 +0800 )edit

I suspect a bug here, I'll contact ZK about it. (created fiddle what support your case : http://zkfiddle.org/sample/3kvld74/23-Tabbox-switching-bug)

chillworld ( 2014-09-24 10:03:51 +0800 )edit
0

answered 2014-09-25 05:09:02 +0800

hawk gravatar image hawk
2255 1 5
http://hawkphoenix.blogsp... ZK Team

updated 2014-09-25 05:32:32 +0800

The root cause of the error of this zkfiddle case, http://zkfiddle.org/sample/3kvld74/23-Tabbox-switching-bug, is that tabbox doesn't allow you to set a null selected tab. Because when you load the page, zk will set vm.selectedTab to tabbox for @bind(vm.selectedTab), for that moment, vm.selectedTab is null.

If you want to control selected tab, you can bind int to "selectedIndex" of a tabbox.

For principle of MVVM pattern, ViewModel should not hold any reference to any component. The principle doesn't encourage users to pass components as parameters to a ViewModel. If you want to change a tabpanel's visibility, you should bind a VM's boolean property to tabpanel "visible" attribute, e.g.

<tabpanel visible="@bind(vm.visible")>

instead of passing that tabpanel to a command method and call tabpanel.setVisible().

link publish delete flag offensive edit

Comments

I agree with hawk: see this updated fiddle and notice the tab and panel are null initially http://zkfiddle.org/sample/3kvld74/24-Tabbox-switching-bug the @SelectorParam cannot resolve them because they are added later (after @Init) to the component tree

cor3000 ( 2014-09-25 08:20:31 +0800 )edit
0

answered 2014-09-25 07:28:17 +0800

cor3000 gravatar image cor3000
4366 2 7
ZK Team

updated 2014-09-25 07:39:40 +0800

Just to take Tabbox in MVVM a step further:

from ZK7 on to enable adding and removing Tabs dynamically in MVVM you can use a ListModel and template to control the tabs and selection without accessing the components at all.

also check this example on zkfiddle

Robert

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
2 followers

RSS

Stats

Asked: 2014-09-22 14:46:47 +0800

Seen: 89 times

Last updated: Sep 25 '14

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