-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have used the same controller for Two Different Zul Files....I have a button(New) and Listbox(Listbox_Customer)in the First Zul and a listbox(listbox_Name) In the second Zul...
When i click the New Button My Event is Firing Twice ..Can any one Explain me why this is Happening
<?xml version="1.0" encoding="UTF-8"?> <?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?> <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?> <zk xmlns="http://www.zkoss.org/2005/zul" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd"> <window apply="${customerCIFListCtrl}" height = "auto"> <listbox model="${customerCIFListCtrl}" itemRenderer="${itemRenderer}" vflex="true" tooltiptext="${c:l('listbox.tooltiptext')}" width="100%" height="100%"> <listhead sizable="true"> <listheader label="${c:l('listheader_ProdCode.label')}" sort="auto" width="40%" /> <listheader label="${c:l('listheader_LeadGenerated.label')}" sort="auto" width="10%" /> <listheader label="${c:l('listheader_SystemGenerated.label')}" sort="auto" width="10%" /> <listheader label="${c:l('listheader_RecordStatus.label')}" sort="auto" width="20%" /> <listheader label="${c:l('listheader_RecordType.label')}" sort="auto" width="20%" /> </listhead> </listbox> </window> </zk>
<?xml version="1.0" encoding="UTF-8"?> <?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?> <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?> <zk xmlns="http://www.zkoss.org/2005/zul" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd"> <window id="window_CustomerCIFList" apply="${customerCIFListCtrl}" border="none" width="100%"> <panel id="panel_CustomerList" title="${c:l('panel_CustomerList.title')}" border="none" /> <div sclass="z-toolbar" style="padding:0" height="28px"> <hbox pack="stretch" sclass="hboxRemoveWhiteStrips" width="100%"> <!-- COMMON BUTTONS --> <toolbar align="start" style="float:left; border-style: none;" width="150px"> <hbox align="center" style="padding: 2px"></hbox> </toolbar> <!-- SEARCH AREA --> <toolbar align="center" style="float:left; border-style: none;"> <hbox align="center" style="padding: 2px"> <button id="button_CustomerList_CustomerSearchDialog" height="24px" image="/images/icons/filter.png" tooltiptext="${c:l('button_CustomerList_CustomerSearchDialog.tooltiptext')}" /> <button id="button_CustomerList_PrintList" height="24px" image="/images/icons/print.png" tooltiptext="${c:l('button_CustomerList_PrintList.tooltiptext')}" /> </hbox> </toolbar> <!-- CRUD BUTTONS --> <toolbar align="end" style="float:right; border-style: none;"> <button id="button_CustomerList_NewCustomer" height="24px" image="/images/icons/addnew.png" tooltiptext="${c:l('button_CustomerList_NewCustomer.tooltiptext')}" /> <button id="btnRefresh" height="24px" image="/images/icons/reload.png" tooltiptext="${c:l('btnRefresh.tooltiptext')}" /> <button id="btnHelp" height="24px" image="/images/icons/help.png" tooltiptext="${c:l('btnHelp.tooltiptext')}" /> </toolbar> </hbox> </div> <borderlayout id="borderLayout_CustomerList"> <north border="none" /> <center border="none"> <grid id="listBoxCustomer" vflex="true" tooltiptext="${c:l('listbox.tooltiptext')}" width="100%" height="100%"> <columns sizable="true"> <column width="40px" /> <column id="listheader_CustCIF" label="${c:l('listheader_CustCIF.label')}" sort="auto" /> <column id="listheader_CustSalutationCode" label="${c:l('listheader_CustSalutationCode.label')}" sort="auto" /> <column id="listheader_CustFName" label="${c:l('listheader_CustFName.label')}" sort="auto" /> <column id="listheader_CustMName" label="${c:l('listheader_CustMName.label')}" sort="auto" /> <column id="listheader_CustLName" label="${c:l('listheader_CustLName.label')}" sort="auto" /> <column id="listheader_CustPassportNo" label="${c:l('listheader_CustPassportNo.label')}" sort="auto" /> <column id="listheader_CustMobileNo" label="${c:l('listheader_CustMobileNo.label')}" sort="auto" /> </columns> </grid> </center> <south border="none"> <paging id="pagingCustomerList" height="35px" /> </south> </borderlayout> </window> </zk>
public void onClick$button_CustomerList_NewCustomer(Event event) throws Exception { System.out.println("Clicked"); }
It seems the same controller instance is used at both places. When the controller is initialized at both places, the event listener is added twice, so it will respond to button_CustomerList_NewCustomer twice on each of the zul page. You can either use different instance of controller, or dodge the button names like:
public void onClick$button1(Event event) { doBtnClick(event); } public void onClick$button2(Event event) { doBtnClick(event); } private void doBtnClick(Event event) { // your logic here }
Regards.
Asked: 2011-07-19 04:27:14 +0800
Seen: 314 times
Last updated: Jul 25 '11