0

How to use same controller for Two Different Zul Files

asked 2011-07-19 04:27:14 +0800

chaitu405 gravatar image chaitu405
93 1

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

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2011-07-19 04:35:03 +0800

SimonPai gravatar image SimonPai
1696 1

Can you provide runnable sample code that shows the issue?

Regards,
Simon

link publish delete flag offensive edit

answered 2011-07-19 04:39:32 +0800

chaitu405 gravatar image chaitu405
93 1

updated 2011-07-19 04:42:49 +0800

<?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>
These 2 are the zul Files i have used with the same Controller. Click Event For the Above New Button
public void onClick$button_CustomerList_NewCustomer(Event event) throws Exception {
	System.out.println("Clicked");
	}
link publish delete flag offensive edit

answered 2011-07-25 02:59:01 +0800

SimonPai gravatar image SimonPai
1696 1

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.

link publish delete flag offensive edit

answered 2011-07-25 04:23:08 +0800

chaitu405 gravatar image chaitu405
93 1

@SimonPai .. Thanks for your reply .. Have changed the code to 2 different instance of controller

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2011-07-19 04:27:14 +0800

Seen: 314 times

Last updated: Jul 25 '11

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