0

problem passing params between pages using execution scope

asked 2009-05-14 15:10:33 +0800

kasperlcurtis gravatar image kasperlcurtis
9 1 1

Hello there,

i have trouble passing parameters between one zul-Page and another.
Let's say, i have the zul-Pages a.zul and b.zul and corresponding composers (extending GenericForwardComposer) A.java and B.java.
a.zul contains a button

<button id="login" />

, the corresponding onClick-Method in Composer A.java looks like this

public void onClick$login(Event event)
{
execution.setAttribute("testkey", "testval");
String testAttribute = (String) execution.getAttribute("testkey");
System.out.println("testAttribute before redirect: " + testAttribute);
execution.sendRedirect("b.zul");
}

The attribute is logged correctly, also page b.zul is loaded.
In Composer B.java the doAfterCompose-Method looks like this:

@Override
public void doAfterCompose(Component comp) throws Exception
{
super.doAfterCompose(comp);
String testAttribute = (String) ((HttpServletRequest) execution
.getNativeRequest()).getAttribute("testkey");
System.out.println("testAttribute after redirect(getAttribute): "
+ testAttribute);
testAttribute = (String) ((HttpServletRequest) execution
.getNativeRequest()).getParameter("testkey");
System.out.println("testAttribute after redirect(getParameter): "
+ testAttribute);
testAttribute = (String) execution.getAttribute("testkey");
System.out
.println("testAttribute after redirect(execution.getAttribute): "
+ testAttribute);
testAttribute = (String) execution.getParameter("testkey");
System.out
.println("testAttribute after redirect(execution.getParameter): "
+ testAttribute);
}

All the values printed here are null.

If i use
session.setAttribute("testkey", "testval");
and
String testAttribute = (String) session.getAttribute("testkey");
the attribute is retrieved correctly.

What the hack am i missing?
I don't want to use the session scope for passing parameters.

Thanks for your help!

(ZK Version is 3.6.0)

delete flag offensive retag edit

20 Replies

Sort by ยป oldest newest

answered 2009-05-14 16:58:04 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

take a look at the search function here in the forum:

Search for "passing param"

You'll find many threads and tricks.

Stephan

link publish delete flag offensive edit

answered 2009-05-15 07:10:03 +0800

kasperlcurtis gravatar image kasperlcurtis
9 1 1

@terrytornado:
Be sure that I already did that. Based on the search result i created the code mentioned above.
Is there an obvioous mistake/misunderstanding that i'm too blind too see? If so, would you please tell me?
Else, your post is not too helpful...
Thanks anyway.

link publish delete flag offensive edit

answered 2009-05-15 08:00:39 +0800

kasperlcurtis gravatar image kasperlcurtis
9 1 1

OK, i found this quote:
If "Executions.sendRedirect() ... is fired, the previous request no longer exists, so you cannot get the attribute saved in the previous request."
Can somebody state that this is true?
So, the next bigger scope to store parameters for inter-zul-page communication is the session scope if you don't want to put parameters in the URL (so that the beaviour is like submitting a form with method="POST").

link publish delete flag offensive edit

answered 2009-05-15 09:37:29 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-05-15 09:38:38 +0800

@kasperlcurtis

I can only read for me. At i'm begin with zkoss i have a very helpful Skype call with
hne that helps me to understand how it's all stick together.
In this call he sends me code for a BaseControler and code fragments for passing params.
With this in mind i have at no times problems to access params from other zul-files because
i'm overhanded not only a param, if needed i overhanded the whole controller object.
The mainly class is the BaseController, he does the work in background.

There are code for a whole module Listbox (onDoubleClick)--> dialog (workWithParams) (changesMadeVisibleToUnderlayingListbox)

Take a look on it here
. Perhaps it can be helpfull.

regards
Stephan

link publish delete flag offensive edit

answered 2011-02-22 03:40:04 +0800

yaryan997 gravatar image yaryan997
210 2

@terrytornado.

HI.. terrytornado.

for your help to solve my problem. Actually I want to say you that either the link is dead or removed to some where else, so IF possible for you to send me the code which you had used to solve problems to pass parameter..

thanx.

link publish delete flag offensive edit

answered 2011-02-22 10:45:51 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2011-02-22 10:47:28 +0800

This is the old link and it's old stuff. It's better to have a look on an annotated databinded module. Make a checkout fom this sample application and debug the ~/webui/branch module.

best
Stephan

link publish delete flag offensive edit

answered 2011-02-23 01:52:44 +0800

yaryan997 gravatar image yaryan997
210 2

updated 2011-02-23 01:53:29 +0800

@terrytornado.

thanx for your help but my problem still 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>
						<button id="REFRESH" label="REFRESH"></button>
					</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);
					}
					
					
			}
				
		});
		
		
		/*.subscribe(new EventListener(){
				public void onEvent(Event event) throws Exception {
				setMsg((String) event.getData());
				service.setValue(msg);			
			}
		});		
		
		
		EventQueues.lookup("myEventQu", EventQueues.DESKTOP, true)
		.subscribe(new EventListener(){
			public void onEvent(Event event) throws Exception {
			//baseController.setSeason_id((String) event.getData());
			//msg1 =(String) event.getData();
			setMsg1((String) event.getData());
			season.setValue(msg1);			
		}
	});*/
	}
	

but when i Click the refresh button 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 think that

Executions.createComponents("tradition.zul", null, map);

is for creating a new component.

What's there the problem in my code.??
help me to solve this error

Best Regards
Yogendra

link publish delete flag offensive edit

answered 2011-02-23 05:31:26 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

Hi Yogendra,

show us the code from the methode that the Button with id="REFRESH" are calling.

link publish delete flag offensive edit

answered 2011-02-23 23:08:17 +0800

yaryan997 gravatar image yaryan997
210 2

@terrytornado

thanx for your support

my referesh BUTTON CODE IS given below and whose declaration is in my basecontroller controller

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);
	}

when user click the refresh button the map will take the service_id and season_id value and pass the param to tradition.zul page
it calls the doAfterCompose method to get the params value passed from the refresh button click event.

	@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);
					}
					
					
			}
				
		});
		


if not able to understand is it the right way to get values passed from one zul to another zul page. And when I execute the page it shows me

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

link publish delete flag offensive edit

answered 2011-02-24 04:45:01 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2011-02-24 04:46:29 +0800

Is the 'retailers_win' a modal window?

1. If not you must be sure that the window is closed ( winName.detach() ) before you create it new.
2. You can call a method in the allready created Window which handles your stuff.

not tested code

composer.java

. . .
// InstanzVar
private Window winRetailer; 

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() );

        if (winRetailer != null ) {
		winRetailer = (Window) Executions.createComponents("tradition.zul", null, map);
	} else {
              winRetailer.callAMethodWhichWillHandleYourStuff( map );
       }


best
Stephan

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: 2009-05-14 15:10:33 +0800

Seen: 2,768 times

Last updated: Mar 03 '11

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