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 2011-02-24 04:49:57 +0800

yaryan997 gravatar image yaryan997
210 2

updated 2011-02-24 05:50:16 +0800

@terrytornado

thanx for your help.. ok that's fine but can you tell me how to get the value from the filterbar.zul page controller to my traditional.zu controller.

So can you plz help me to get that value in my traditional controller so I can use them again for executing some queries with that controller.

Best Regards
Yogendra Singh

link publish delete flag offensive edit

answered 2011-02-24 05:45:28 +0800

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

updated 2011-02-24 05:46:40 +0800

callAMethodWhichWillHandleYourStuff( Map<String, Object> map ) {

		if (map.containsKey("service_id")) {
                        // CAST to your needed type. Don't know it.
			setServiceID(   ( int )  map.get("service_id"));
                }

		if (map.containsKey("season_id")) {
                        // CAST to your needed type. Don't know it.
			setSeasonID(   ( int )  map.get("season_id"));
                }

          // Do some other stuff with it

}

best
Stephan

link publish delete flag offensive edit

answered 2011-03-01 02:35:36 +0800

yaryan997 gravatar image yaryan997
210 2

updated 2011-03-02 05:49:12 +0800

@terrytornado

Hi.. terry with your support I am able to solve my problem of passing params from one controller filter_bar to traditional_retailer controller.

Now I want to use that filter_bar.zul page and it's controller inside my traditional.zul with tradtional_retailer controller I am get the one error.

java.lang.NullPointerException
	at com.certilogo.ecc.controller.BaseController.onCreate$filter_bar(BaseController.java:78)
	at com.certilogo.ecc.services.TraditionalRetailers.doAfterCompose(TraditionalRetailers.java:110)


My traditional_retailer controller class has a doAfterCompose() method which calls the baseController OnCreate$Filter_bar has code given below

 public void doAfterCompose(Component comp) throws Exception {
		 super.doAfterCompose(comp);
		 logger.info("YOu have pressed a hellow button ");
		 this.onCreate$filter_bar();
	 }

the onCreate$filter_bar() method inside basecontroller in given below

public void onCreate$filter_bar() throws Exception {
		logger.info("ON CREATE EXECUTE");
		System.out.println("Create");
		
		lbox_service.setModel(new ListModelList(getCertilogoServiceDao().getAllServices()));		
		lbox_season.setModel(new ListModelList(getCertilogoServiceDao().getAllSeason()));
				
		logger.info("Done");
	}

but as soon as onCreate$filter bar of BaseController run it throws me an error.

java.lang.NullPointerException
	at com.certilogo.ecc.controller.BaseController.onCreate$filter_bar(BaseController.java:78)
	at com.certilogo.ecc.services.TraditionalRetailers.doAfterCompose(TraditionalRetailers.java:110)

My Filter_bar.zul page has code given below

<?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="filter_bar"
		border="none"
		apply="${baseController}" closable="false" width="800px" height="520px"
		sizable="true">
		<grid>
			<columns>
				<column label="Select Service" width="50%">
					<listbox id="lbox_service" mold="select" rows="1">
						<listitem self="@{each=each1}" label="@{each1.serviceName}" value="@{each1.serviceId}"/>
					</listbox>
				</column>
				
				<column label="Select Season" width="50%">
					<listbox id="lbox_season" mold="select" rows="1">
						<listitem self="@{each=each1}" label="@{each1.season}" value="@{each1.seasonId}"/>
					</listbox>
				</column>
				
			</columns>
		</grid>
		
		
	</window>
</zk>


and my tradition_retailer.zul page is given below

<?page title="Traditional Page" contentType="text/html;charset=UTF-8" ?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<zk>
<window id="traditional" title="Traditional Page" border="normal" apply="${traditional_retailers}">

<button id="Hello1" label="Click Me"/>
<button id="Hello" label="Button in Tradition"></button>
</window>
</zk>


my lbox_service.setModel(new ListModelList(getCertilogoServiceDao().getAllServices())); contains following code


@SuppressWarnings("unchecked")
	public List getServices(String serviceIds) {
		// TODO Auto-generated method stub
		System.out.println("Executing Service");
		System.out.println("Service Id>> " +serviceIds);
		Query query;
		if(serviceIds.equals("") || serviceIds.equals(null)) {
			query = entityManager.createQuery("SELECT new map (s.serviceId as serviceId, s.serviceName as serviceName) from CertilogoService s");
		} else {
			query = entityManager.createQuery("SELECT new map (s.serviceId as serviceId, s.serviceName as serviceName) from CertilogoService s where serviceId in("+serviceIds+")");
		}
		
		//List<HashMap> srcList = new ArrayList(); 
		List result = query.getResultList();
	
		
		/*for(Object obj : result) {
			CertilogoService service = (CertilogoService) obj;
			System.out.println("Certilogo Service :" +service.getServiceId());
		}
		*/
		System.out.println("Result Value :" +result.get(0));
		System.out.println("Query :" +result);
		
		return result;

	}


Actually when I run the filter_bar.zul page separately it runs fine .. but when I run traditional_retailer.zul page that has included filter_bar.zul it throws me the above error..

Best Regards
Yogendra

link publish delete flag offensive edit

answered 2011-03-02 07:18:09 +0800

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

updated 2011-03-02 07:23:56 +0800

1. Do you work with the spring framework?


2.

 		 
 public void doAfterCompose(Component comp) throws Exception {
		 super.doAfterCompose(comp);
		 logger.info("YOu have pressed a hellow button ");
===>	 this.onCreate$filter_bar();
	 }

Why not going the 'normal' way with Window win = (Window) Executions.createComponents( "Filter_bar.zul" , , map);

link publish delete flag offensive edit

answered 2011-03-02 23:58:18 +0800

yaryan997 gravatar image yaryan997
210 2

@ terrytornado

Actually why I am not using Window win = (Window) Executions.createComponents( "Filter_bar.zul" , , map);

because Once the Solution I get and my window get's created and when again when I click any button in filter_bar.zul like refresh button to get my LIstbox_service and Listbox_season value . and want to execute query based on them I get

not Unique Id space owner error...

Best Regards
YOgendra

link publish delete flag offensive edit

answered 2011-03-03 03:06:05 +0800

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

updated 2011-03-03 03:07:33 +0800

This is AJAX. Normally it's enough that your REFRESH button calls a methode that actualize the ListModelList. Means this refreshes your data. The rendering is doing by zk.

best
Stephan

link publish delete flag offensive edit

answered 2011-03-03 04:25:32 +0800

yaryan997 gravatar image yaryan997
210 2

@Terrytornado

you are very much help full but I am not getting it done by myself....
I had read your one forum posting for not the creation of multiple component but, when I implemented that I creates a new Component ..

I am giving you my full source code.. plz refer them and let me know what I am doing wrong.

Traditional1.zul page

<?page id="main_window" title="Traditional Page" contentType="text/html;charset=UTF-8" ?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<zk>
<window id="traditional" title="Traditional Page" border="normal" apply="${traditional_retailers}">
<include src="filter_bar.zul?pageId=first"/>
</window>
</zk>

my Filter_bar.zul page is

<?xml version="1.0" encoding="UTF-8" ?>
<?page id="first" contentType="text/html;charset=UTF-8" ?>
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
<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="filter_bar"
		border="none"
		apply="${baseController}" closable="false" width="800px" height="520px"
		sizable="true">
		<grid>
			<columns>
				<column label="Select Service" width="50%">
					<listbox id="lbox_service" mold="select" rows="1" model="@{controller.allServices}">
						<listitem self="@{each=each1}" label="@{each1.serviceName}" value="@{each1.serviceId}"/>	
					</listbox>
				</column>
				
				<column label="Select Season" width="50%">
					<listbox id="lbox_season" mold="select" rows="1" model="@{controller.seasonListCombo}">
						<listitem self="@{each=each1}" label="@{each1.season}" value="@{each1.seasonId}"/>
					</listbox>
				</column>
				
				<column width="35%">
					<button id="hello" label="Plz Press Me"/>
				</column>
			</columns>
	</grid>				
	</window>
</zk>

my traditional_retailers controller class is

/**
 * 
 */
package com.certilogo.ecc.services;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zul.Button;
import org.zkoss.zul.Include;
import org.zkoss.zul.Window;

import com.certilogo.ecc.backend.services.VerificationStoreHibernateDao;
import com.certilogo.ecc.controller.BaseController;

/**
 * @author Yogendra
 *
 */
public class TraditionalRetailers extends BaseController implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected Window traditional;
	protected Include filter;
	protected String seasonId = "0";
	protected String service_id = "0";
	final Log logger = LogFactory.getLog(getClass());
	
	protected VerificationStoreHibernateDao verificationStoreHibernateDao;
	
	public String getSeasonId() {
		return seasonId;
	}

	public void setSeasonId(String seasonId) {
		this.seasonId = seasonId;
	}

	public String getService_id() {
		return service_id;
	}

	public void setService_id(String serviceId) {
		service_id = serviceId;
	}
	
	 private void setParams(Map<String, Object> args) {
			// TODO Auto-generated method stub
		 if(args.containsKey("service_id")) {
				//this.setSeasonId(map.get("service_id"));
				logger.info("SErveic in Param :"+args.get("service_id"));
				//this.setService_id()
				this.setService_id(args.get("service_id").toString());
			}
			
			if(args.containsKey("season_id")) {
				//this.setSeasonId(map.get("service_id"));
				logger.info("Season in Param :"+args.get("season_id"));
				this.setSeasonId(args.get("season_id").toString());
			}
		}
	 
	public void onCreate$traditional(Event event) throws Exception {
		//self.detach();
		// Executions.createComponents("filter_bar.zul", null,null);
		
		System.out.println("Window Allreadey creatde for you babes");
		System.out.println("Page Id Traditional You Selected :" +self.getId());
		System.out.println("getService_id initially :" +getService_id());
		System.out.println("getSeasonId initially :" +getSeasonId());
		
		Map<String, Object> args = getCreationArgsMap(event);
		
		if(args.containsKey("service_id")) {
			System.out.println("Service Id >>:"+args.get("service_id"));
			//service_id = args.get("service_id").toString();
			
			this.setService_id(args.get("service_id").toString());
		}else {
			System.out.println("None SErvice");
			this.setService_id("0");
		}
		
		if(args.containsKey("season_id")) {
			System.out.println("Season Id >>>:"+args.get("season_id"));
			//seasonId = args.get("season_id").toString();
			this.setSeasonId(args.get("season_id").toString());
		}else {
			System.out.println("None Season");
			this.setSeasonId("0");
		}		
		
	/*	if(traditional == null) {
			traditional = (Window) Executions.createComponents("traditional.zul", null, args);
		} else {
			System.out.println("Error with loading Traditional the page");
			this.setParams(args);
		}*/
		
		
		this.getService_id();
		this.getSeasonId();
		
		logger.info("Service Id Traditional :"+this.getService_id());
		logger.info("Season Id Traditional :"+this.getSeasonId());
		/*
		Map<String, Object> args = getCreationArgsMap(event);
		
		if(args.containsKey("service_id")) {
			System.out.println("Service Id >>:"+args.get("service_id"));
			//service_id = args.get("service_id").toString();
			
			this.setService_id(args.get("service_id").toString());
		}else {
			System.out.println("None SErvice");
			this.setService_id("0");
		}
		
		if(args.containsKey("season_id")) {
			System.out.println("Season Id >>>:"+args.get("season_id"));
			//seasonId = args.get("season_id").toString();
			this.setSeasonId(args.get("season_id").toString());
		}else {
			System.out.println("None Season");
			this.setSeasonId("0");
		}
		
		String dateFrom = "";
		String dateTo = "";
		String order = "2";
		List TDRetailers = verificationStoreHibernateDao.getTraditionalRetailers(getService_id(),getSeasonId(),dateFrom,dateTo,order);
		
		System.out.print("TDretailes :" +TDRetailers);
		*/
		
	}
	
	

	public void doAfterCompose(Component comp) throws Exception {
		 super.doAfterCompose(comp);
		 logger.info("YOu have pressed a hellow button ");
		 //self.detach();
				  
	 }
	 
	 public void onClick$refresh(Event event) throws Exception {
		 logger.info("Service Id "+this.getService_id());
		 logger.info("Season Id "+this.getSeasonId());
		
	 }
	 
}


my baseController CONTROLLER CLASS IS

/**
 * 
 */
package com.certilogo.ecc.controller;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.python.core.exceptions;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.CreateEvent;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.ForwardEvent;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zkplus.databind.AnnotateDataBinder;
import org.zkoss.zkplus.databind.BindingListModelList;
import org.zkoss.zkplus.databind.DataBinder;
import org.zkoss.zul.Button;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Window;

import com.certilogo.ecc.backend.entities.CertilogoService;
import com.certilogo.ecc.backend.entities.CusSeason;
import com.certilogo.ecc.backend.services.CertilogoServiceDao;
import com.certilogo.ecc.frontend.SeasonListModelItemRenderer;
import com.certilogo.ecc.frontend.ServiceListModelItemRenderer;
import com.certilogo.ecc.services.TraditionalRetailers;

/**
 * @author Yogendra
 *
 */
@SuppressWarnings("unused")
public class BaseController extends GenericForwardComposer implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	final Log logger = LogFactory.getLog(getClass());
	
	protected Window filter_bar,traditional;
	protected TraditionalRetailers tr1;
	protected Button Hello1;
	protected Listbox lbox_service;
	protected Listbox lbox_season;
	protected ListModelList listModel;

	private String seasonId = "0";
	private String service_id = "0";
	
	private CertilogoServiceDao certilogoServiceDao;
	private AnnotateDataBinder binder;

	protected transient Map<String, Object> args;
	protected TraditionalRetailers tr;
	
	final Map<String,Object> map = new HashMap<String,Object>(0);
	
	@SuppressWarnings("unchecked")
	public Map<String, Object> getCreationArgsMap(Event event) {
		CreateEvent ce = (CreateEvent) ((ForwardEvent)event).getOrigin();
		return ce.getArg();
	}
	
	public void doOnCreateCommon(Window w, Event fe) throws Exception {
		CreateEvent ce = (CreateEvent) ((ForwardEvent) fe).getOrigin();
		args = ce.getArg();
	}
	 
	public void onCreate$filter_bar(ForwardEvent event) throws Exception {
		logger.info("ON CREATE EXECUTE");
		System.out.println("Create");
		System.out.println("TWO");
		
		//ListModelList
			
		lbox_season.setModel(new ListModelList(getCertilogoServiceDao().getAllSeason()));
		lbox_service.setModel(new ListModelList(getCertilogoServiceDao().getAllServices()));
		//lbox_service.setItemRenderer(new ServiceListModelItemRenderer());
		
		ListModelList lml_service = (ListModelList) lbox_service.getModel();
		ListModelList lml_season = (ListModelList) lbox_season.getModel();
				
		lml_service.add(0, "All");
		lml_season.add(0, "All");

		System.out.println("THREE");
		
		logger.info("Done");
	}
	
	public void setCertilogoServiceDao(CertilogoServiceDao certilogoServiceDao) {
		this.certilogoServiceDao = certilogoServiceDao;
	}

	public CertilogoServiceDao getCertilogoServiceDao() {
		return certilogoServiceDao;
	}
	
	public String getSeasonId() {
		return seasonId;
	}

	public void setSeasonId() {
		logger.info("Season Id After Params"+this.getSeasonId());
		this.seasonId = this.lbox_season.getSelectedItem().getValue().toString();
	}

	public String getService_id() {
		return service_id;
	}

	public void setService_id() {
		logger.info("SErvice Id After Params"+this.getService_id());
		service_id = this.lbox_service.getSelectedItem().getValue().toString();
	}

	public void onClick$hello(Event event) throws Exception {
		
		this.setService_id();
		this.setSeasonId();
		System.out.println("Page Id BaseController You Selected :" +self.getId());
		//tr1.setParams("23");
			if(lbox_service != null || lbox_season != null) {
		
			logger.info("Service Id :"+this.getService_id());
			logger.info("Season Id :"+this.getSeasonId());
			
			map.put("service_id", this.getService_id());
			map.put("season_id", this.getSeasonId());
			map.put("baseController", this);
			
			if(filter_bar != null) {
				//traditional.setVisible(true);
				System.out.println("Createing window for you");
				traditional = (Window) Executions.createComponents("traditional1.zul", null, map);
				traditional.setId((String)map.get("type"));
			} else {
				this.savePrams(map);
				System.out.println("Error with loading the page");
			}
			
			
		}else {
			System.out.println("Error with the page");
		}
		
		this.filter_bar.invalidate();
	}
	
	 public void savePrams(Map<String, Object> map2) {
		// TODO Auto-generated method stub
		if(map2.containsKey("service_id")) {
			//this.setSeasonId(map.get("service_id"));
			logger.info("SErveic in Param :"+map2.get("service_id"));
			this.setService_id();
		}
		
		if(map2.containsKey("season_id")) {
			//this.setSeasonId(map.get("service_id"));
			logger.info("Season in Param :"+map2.get("season_id"));
			this.setService_id();
			//this.setSeasonId(args.get("season_id").toString());
		}
	}

	public void doAfterCompose(Component comp) throws Exception {
		 super.doAfterCompose(comp);
		 logger.info("YOu have pressed a hellow button ");
		 //traditional.detach();
		
	 }

	@SuppressWarnings("deprecation")
	public List<CertilogoService> getAllServices() {
		return CertilogoServiceDao.getInstance().getAllSeason();
	}
}


I am using zk 5.0.4 with eclipse 3.5 along with Spring framework

Help me to solve my problem

Best Regards
YOgendra

link publish delete flag offensive edit

answered 2011-03-03 04:45:46 +0800

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

Yogendra, sorry but this is absolute not possible for me. It's too much code to study and it's a lot of copy and paste from other classes where i do not understand what you will doing.

1. Create a picture from a prototype how it should looks like and save it on a webserver.
2. Are the season_ID and service_ID all times are working together (means if they come from ONE table ??) ?

link publish delete flag offensive edit

answered 2011-03-03 05:40:06 +0800

yaryan997 gravatar image yaryan997
210 2

@Terrytornado..

Actually the value of season_id and service_id value all comes from different class.

and for picture prototype that how it looks Can you please give me you e-mail contact Id so that I can send that to your mail.

Best Regards
YOgendra

link publish delete flag offensive edit

answered 2011-03-03 07:25:39 +0800

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

sge (at) forsthaus (dot) de

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,778 times

Last updated: Mar 03 '11

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