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-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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:-");
}
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.
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 )editThis 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.....
<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>
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.
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 )editI 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 )editThe 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()
.
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 )editJust 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
Asked: 2014-09-22 14:46:47 +0800
Seen: 106 times
Last updated: Sep 25 '14