0

Passing value from one zul file to another zul file

asked 2010-04-27 03:33:10 +0800

Kailas gravatar image Kailas
144 1 1

updated 2010-04-27 03:36:09 +0800

Hi friends, My problem is that passing value from one zul file to another zul file textbox. I am using GenericForwardComposer for MVC architecture. Thsre is a zul file code here
<?page id="memberpage" title="Member Registation" contentType="text/html;charset=UTF-8"?>
<zk>
<window id="winmember" border="normal" width="100%" height="100%" apply="">
	<tabbox height="100%">
	<tabs id="tabs">
		<tab id="tabinfo" label="Information" />
		<tab id="tabregister" label="Registration" />
	</tabs>
	<tabpanels id="tabpanelsearch">
		<tabpanel>
			<include src="/erp/first.zul"/>
		</tabpanel>
		<tabpanel id="tabpanelregister" >
			<include src="/erp/second.zul"/>
		</tabpanel>
	</tabpanels>
</tabbox>
</window>
</zk>

This is first.zul file
<?page id="firstpage"  title="" contentType="text/html;charset=UTF-8"?>
<zk>
<window id="winfirst" border="normal" apply="org.vts.erp.First">
	<grid>
		<rows>
			<row>
				<label value="No" />
				<textbox id="passno"/>	
			</row>
			<row>
				<button id="next" label="next" />
				<button label="cancel" />	
			</row>
		</rows>
	</grid>
</window>
</zk>

This is second.zul file
<?page id="secondpage" title="" contentType="text/html;charset=UTF-8"?>
<zk>
<window id="winsecond" border="normal" apply="org.vts.erp.Second">
	<grid id="passgrid">
		<rows>
			<row>
				<label value="No" />
				<textbox id="passid"/>	
			</row>
			<row>
				<label value="Name" />
				<textbox id="nameid"/>	
			</row>
			<row>
				<button id="nextsecond" label="next" />
				<button label="cancel" />	
			</row>
		</rows>
	</grid>
</window>
</zk>

and corresponding JAVA code
public class First extends GenericForwardComposer 
{

	public Second ss = new Second();
	public Textbox passno;
	public Button next;
	
	public void onClick$next(Event event) throws Exception
	{
		final String no = passno.getText();
		System.out.println("textbox val...."+passno.getText());
		ss.setPassId(no);
	}
}
public class Second extends GenericForwardComposer
{

	public Textbox passid;
	public Button nextsecond;
	
	public void setPassId(final String no) throws Exception
	{
		//doAfterCompose(passid);
		//afterCompose();
		System.out.println("Method is Call....."+no);
		passid.setText(no);
	}
}

When i am click on next button in First.zul file then onClick$next(...) function call. and it call setPassId(final String no) this function and print it's parameter number but it return Null pointer. the textbox (passid) not set parameter value. How to set parameter value to component in Second zul file. Help me Thanks.
delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2010-04-27 08:05:04 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

Your problem stems from the fact that First->ss is NOT the same Second that is referenced in second.zul's apply="org.vts.erp.Second". The apply in second.zul created a new instance of org.vts.erp.Second. So did public Second ss = new Second(); in First. So, they're two distinct instances. When First executes "ss.setPassId(no);", the passid that you're referencing in the last statement of setPassId(final String no) has not been initialized because the instance was created by you and not the ZK framework and thus your NPE.

Also, winfirst and winsecond are window's, so they're different id spaces. You'll probably have to forward an event from winfirst into winsecond.

link publish delete flag offensive edit

answered 2010-04-28 03:14:46 +0800

Kailas gravatar image Kailas
144 1 1

updated 2010-04-28 03:15:47 +0800

Thanks caclark

Yes you are correct. There are tow distinct instances also winfirst and winsecond are window's, so they're different id spaces.

I have solve this problem.

Zul file as it is. Java file is change.

First.java

public class First extends GenericForwardComposer 
{

	public Second ss = new Second();
	public Textbox passno;
	public Button next;
	
	public void doAfterCompose(Component win) throws Exception 
	{
        super.doAfterCompose(win);
    }
	
	public void doRefresh() throws Exception
	{
		doAfterCompose(Path.getComponent("//firstpage/winfirst"));
	}
	
	public void onClick$next(Event event) throws Exception
	{
		final String no = passno.getText();
		System.out.println("textbox val...."+passno.getText());
		ss.setPassId(no);
	}
}

Second.java

public class Second extends GenericForwardComposer
{
	public Textbox passid;
	public Button nextsecond;
		
	public void doAfterCompose(Component win) throws Exception 
	{
        super.doAfterCompose(win);
    }
	
	public void doRefresh() throws Exception
	{
		doAfterCompose(Path.getComponent("//secondpage/winsecond"));
	}
	
	public void setPassId(final String no) throws Exception
	{
		doRefresh();
		passid.setText(no);
	}
}


Try this. and if there is any problem in my code please post message.

link publish delete flag offensive edit

answered 2010-06-10 05:07:22 +0800

vin gravatar image vin
3

ryrtyrt

link publish delete flag offensive edit

answered 2011-02-22 00:48:33 +0800

yaryan997 gravatar image yaryan997
210 2

@Kailas..

HI. .
Kailas I don't know actually how was your problem get resolved, but actually when I run your given code It still gives me that NULL POINTER EXCEPTION. DON'T know what's their the problem.

Can you plz help me to solve that..

link publish delete flag offensive edit

answered 2011-02-23 22:33:35 +0800

Kailas gravatar image Kailas
144 1 1

hi yaryan997

Plz post some code.
i can solve your problem.

link publish delete flag offensive edit

answered 2011-02-24 05:24:54 +0800

yaryan997 gravatar image yaryan997
210 2

@Kailas


thanx for your help but my problem not solved and it throws me another error.

Failed to assign [id=retailers_win] to <Window z_fnr_r7>
Not unique in ID space [Page tra]: retailers_win

my filter_bar.zul page is

<window border="normal" id="filter_bar" class="main_bg" apply="${baseController}">
	<div class="textalign1" style="height:30px;">    	
    	<div style="float:left;" class="style_a5 select_service"></div>
			<div class="textalign2 combo">
  				Brand :<listbox
  						id="lbox_service" width="120px" mold="select"
  						multiple="false" rows="1">
  						
  						<listitem self="@{each=each1}"  label="@{each1.serviceName}" value="@{each1.serviceId}"/>
  				 
					</listbox>
			</div>
			
		<div class="style_a5 select_service2" style="margin-left:35px;" ></div>
		<div style="float:left; margin-left:5px;">
 			<div id="div_seasons" class="combo">
				Season :<listbox
  						id="lbox_season" width="120px" mold="select"
  						multiple="false" rows="1" >
  					
  						<listitem self="@{each=each1}" label="@{each1.season}"  value="@{each1.seasonId}" />
						
  					</listbox>	 
			</div>
		</div>
		
		<div class="style_a5 select_service2" style="margin-left:35px;" ></div>
		<div style="float:left; margin-left:5px;">
 			<div id="div_refresh">
 			Period :<textbox id="period1"></textbox>
				<button id="ref" label="Ref"></button>
			</div>
		</div>
		
		<div class="style_a5 select_service2" style="margin-left:35px;" ></div>
		<div style="float:left; margin-left:5px;">
 			<div  class="combo">
				Month From :<listbox
  						id="monthFrom" width="120px" mold="select"
  						multiple="false" rows="1">
  						
  					</listbox>	 
  					
  				Year From :<listbox
  						id="yearFrom" width="120px" mold="select"
  						multiple="false" rows="1" >
  					</listbox>
  				
  				Month To :<listbox
  						id="monthTo" width="120px" mold="select"
  						multiple="false" rows="1" >
  					</listbox>	
  				
  				Year To :<listbox
  						id="yearTo" width="120px" mold="select"
  						multiple="false" rows="1" >
  					</listbox>	   
			</div>
		</div>
		
		
		
		
	</div>
</window>

and the controller for the filter_bar.zul is baseController.java that has on onClick$ref that will get the value from my filter bar and that has a code

public void onClick$ref(Event event){
		//this.setPeriod();
		final Map<String, Object> map = new HashMap<String, Object>(0);
		map.put("service_id",this.getService_id() );
		map.put("season_id", this.getSeason_id() );
		
		final Window win = (Window)Executions.createComponents("tradition.zul", null, map);
	}

and then my tradition.zul page load that has having controller Traditional_retailers

<zk>
<?page id="tra" title="Traditional" contentType="text/html;charset=UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="retailers_win"?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<include src="filter_bar.zul" />
<window border="normal" id="retailers_win" class="main_bg" apply="${traditionalRetailer1}"
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">
	<div id="product_table" align="left" width="100%" height="100%">
             	
             			<listbox id="retailer" fixedLayout="true" model="@{controller.TDRetailers}"	>
	             			<attribute name="onSelect">
	             			 	<![CDATA[
	             			 	       Messagebox.show(self.getSelectedItem().getChildren().get(0).getLabel());
	             			 	        
									//Messagebox.show("Selected Value : " + self.getSelectedItem().getLabel()+", "+ self.getSelectedItem().getChildren().get(2).getLabel());
								]]>
	             			 </attribute>
						  <listhead>
						   <listheader label="Store Name" width="18%" align="left" />
						   <listheader label="Country" width="14%" align="left"/>
						   <listheader label="City" width="14%" align="left"/>
						   <listheader label="Auth. OK" width="10%" align="center"/>
						   <listheader label="Info. OK" width="10%" align="center"/>
						   <listheader label="Auth. KO" width="10%" align="center"/>
						   <listheader label="Info. KO" width="10%" align="center"/>
						   <listheader label="Auth. Fakes" width="10%" align="center"/>
						   <listheader label="Unq. Invalid" width="10%" align="center"/>
						  </listhead>
						   <listitem self="@{each=each1}" >
						  	<listcell visible="false"  label="@{each1.verification_store_id}"></listcell>
						   	<listcell  label="@{each1.store_name}"  />
						  	<listcell  label="@{each1.country}" />
						  	<listcell  label="@{each1.city_name}" />
						  	<listcell  label="@{each1.auth_ok}" />
						  	<listcell  label="@{each1.info_ok}" />
						  	<listcell  label="@{each1.auth_ko}" />
						  	<listcell  label="@{each1.info_ko}" />
						  	<listcell  label="@{each1.auth_fakes}" />
						  	<listcell  label="@{each1.unique_invalid}" />
						 
						  </listitem>
						 
						 </listbox>
						<label value="${args.service_id}"></label>
						<label value="${args.season_id}"></label>
						
					</div>
					</window>
</zk>

my traditional_retailer.java file having doAfterCompose code is below

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		
		super.doAfterCompose(comp);
		EventQueues.lookup("myEventQueue", EventQueues.DESKTOP, true)
		
		.subscribe(new EventListener() {			
			public void onEvent(Event event) throws Exception {
				/*String service = (String) event.getData();
				
				logger.info("Servive $$$$$$$$$ " + service);
				//String season = (String) event.getData();
				//logger.info("Season $$$$$$$$$ " + season);*/
				
					/*if("service_id".equals(event.getName())) {
					System.out.println("service_id_select :" +event.getData());
					setService_id((String) event.getData());
					baseController.setFilterChanged("true");
					System.out.println("Service Id :" +event.getData());
					}*/
					
					
					if("season_id".equals(event.getName())) {
					setSeason_id((String) event.getData());
					baseController.setFilterChanged("true");
					System.out.println("Season Id :" +event.getData());
					}
					
					logger.info("filter  change : " +baseController.getFilterChanged());
					if(baseController.getFilterChanged().equals("true"))
					{
						String order = "2";
						List TDRetailers = verificationStoreHibernateDao.getTraditionalRetailers(getService_id(), getSeason_id(),dateFrom, dateTo, order);
						//VerificationStoreHibernateDao storeHibernateDao = new VerificationStoreHibernateDao();
						//List TDRetailers = this.verificationStoreHibernateDao.getTraditionalRetailers(service_id);
						//ListModel listModel = this.retailers.getModel();
						ListModelList listModelList = (ListModelList) retailer.getModel();
						listModelList.clear();
						listModelList.addAll(TDRetailers);
					}
					
					
			}
				
		});
		
		

but when i Click the refresh button of the baseController it show's me the error

Failed to assign [id=retailers_win] to <Window z_fnr_r7>
Not unique in ID space [Page tra]: retailers_win

and also I don't know how to get my passed value in my traditional controller class

link publish delete flag offensive edit

answered 2011-03-02 23:52:16 +0800

Kailas gravatar image Kailas
144 1 1

Hi yaryan997

First you have to set Window ID for each Window

and then try this

doAfterCompose(Path.getComponent("//your_page_id/your_window_id"));

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: 2010-04-27 03:33:10 +0800

Seen: 3,484 times

Last updated: Mar 02 '11

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