0

Call a controller class from javascript

asked 2010-12-03 06:00:08 +0800

scerro gravatar image scerro
273 3 9
www.desarrolloagil.es

Hi all,

Could I call a zk controller java file from a javascript function? It's work like a servlet? is there any possibility?

I have a java file extending from Window Class.

thanks!

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2010-12-03 07:22:07 +0800

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

At the top right of the forum, I used the Search box with these terms: javascript send event with the Database (which is really the forum) radio button selected. There's a good list that comes back, one of them with this link: Updating Server side per JavaScript

link publish delete flag offensive edit

answered 2011-02-16 05:33:52 +0800

yaryan997 gravatar image yaryan997
210 2

@caclark:-

Hi.....

I am also having one problem for passing the value from one controller to another one.
I am having one BaseController which is extended by my other classes. The problem is that there are two separate controller i am using one is for the filter bar and the other is for my traditional_retailer class..

When the programme run's the traditional_retailer.zul page has two controller with it. The first controller is used by the Filter bar and the other one is for the traditional_retailer class.

When i select the values from the filter bar having the listbox the values goes to my basecontroller class but, when i want that value in my traditional_retailer class it gives me nothing..

So.. plz help me to solve my problem.

my filter.zul page is

<zk>
<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">
				<button id="ref" label="Ref"></button>
			</div>
		</div>
		
	</div>
</window>
</zk>


my baseController is

public class BaseController extends GenericForwardComposer implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	protected transient Map<String, Object> args;
	
	protected Listbox lbox_season;
	protected Listbox lbox_service;
	private String service = "0";
	
	@SuppressWarnings("unchecked")
	public Map<String, Object> getCreationArgsMap(Event event) {
		CreateEvent ce = (CreateEvent) ((ForwardEvent) event).getOrigin();
		return (Map<String, Object>) ce.getArg();
	}
	
	@SuppressWarnings("unchecked")
	public void doOnCreateCommon(Window w,Event fe) throws Exception {
		CreateEvent ce = (CreateEvent) ((ForwardEvent) fe).getOrigin();
		args = (Map<String, Object>) ce.getArg();
	}
	
	private CertilogoServiceDao certilogoServiceDao;
	
	public void onEvent(Event evt) throws Exception {
		final Object controller = getController();
		final Method mtd = ComponentsCtrl.getEventMethod(controller.getClass(), evt.getName());
		
		super.onEvent(evt);
	}


	/**
	 * @return the certilogoServiceDao
	 */
	public CertilogoServiceDao getCertilogoServiceDao() {
		return certilogoServiceDao;
	}

	/**
	 * @param certilogoServiceDao the certilogoServiceDao to set
	 */
	public void setCertilogoServiceDao(CertilogoServiceDao certilogoServiceDao) {
		this.certilogoServiceDao = certilogoServiceDao;
	}
	
	public void onCreate$filter_bar(Event event) throws Exception{
		
		System.out.println("OnCreate!!!!");
		
	/*	List service = certilogoServiceDao.getAllServices();
		ListModelList lml = (ListModelList)getLbox_service().getModel();
		lml.clear();
		lml.add(0, "All");
		lml.addAll(service);
		lml.addAll(service);*/
		lbox_service.setModel(new ListModelList(certilogoServiceDao.getAllServices()));
		//lbox_service.setItemRenderer(new ServiceListModelItemRenderer());
		
		lbox_season.setModel(new ListModelList(certilogoServiceDao.getAllSeason()));
		//lbox_season.setItemRenderer(new SeasonListModelItemRenderer());
		
		System.out.println("Before listmodellist");
		ListModelList lml_service = (ListModelList) lbox_service.getModel();
		ListModelList lml_season = (ListModelList) lbox_season.getModel();
		//lml_service.add(0, "All");
		//lml_season.add(0, "All");
		
		//lbox_service.setSelectedIndex(-1);
		//lbox_season.setSelectedIndex(-1);
		//setService();
		System.out.println("After listmodellist");
		
	}

	/**
	 * @return the lbox_season
	 */
	public Listbox getLbox_season() {
		return lbox_season;
	}

	/**
	 * @return the lbox_service
	 */
	public Listbox getLbox_service() {
		return lbox_service;
	}

	/**
	 * @param lboxSeason the lbox_season to set
	 */
	public void setLbox_season(Listbox lboxSeason) {
		lbox_season = lboxSeason;
	}

	/**
	 * @param lboxService the lbox_service to set
	 */
	public void setLbox_service(Listbox lboxService) {
		lbox_service = lboxService;
	}
	
	public void onClick$refresh(Event e)throws Exception
	{
		System.out.println("Service : " +lbox_service.getSelectedItem().getValue());
		System.out.println("Season : " +lbox_season.getSelectedItem().getValue());
	}
	public void onClick$ref()
	{
		String item1 = this.lbox_service.getSelectedItem().getValue().toString();
		String item2 = this.lbox_season.getSelectedItem().getValue().toString();
		
		System.out.println("Service : " +item1);
		System.out.println("Season : " +item2);
		
		
	}

	/**
	 * @param service the service to set
	 */
	public void setService() {
		this.service = lbox_service.getSelectedItem().getValue().toString();
		System.out.println("Service : " + service);
	}

	/**
	 * @return the service
	 */
	public String getService() {
		return service;
	}
}

my traditional_retailer class is

public class TraditionalReailers1 extends BaseController
{
	private Listbox retailer;
	Grid retailers1;
	final Log logger = LogFactory.getLog(getClass());
	private CertilogoService certilogoService;
	protected transient AnnotateDataBinder binder;
	
	/**
	 * @return the retailer
	 */
	public Listbox getRetailer() {
		return retailer;
	}

	/**
	 * @param retailer the retailer to set
	 */
	public void setRetailer(Listbox retailer) {
		this.retailer = retailer;
	}

	protected VerificationStoreHibernateDao verificationStoreHibernateDao = new VerificationStoreHibernateDao();

	/*public void doAfterCompose(Component comp) throws Exception 
	{
		super.doAfterCompose(comp);
		
	}*/
	
	/**
	 * @return the verificationStoreHibernateDao
	 */
	public VerificationStoreHibernateDao getVerificationStoreHibernateDao() {
		return verificationStoreHibernateDao;
	}

	/**
	 * @param verificationStoreHibernateDao the verificationStoreHibernateDao to set
	 */
	public void setVerificationStoreHibernateDao(
			VerificationStoreHibernateDao verificationStoreHibernateDao) {
		this.verificationStoreHibernateDao = verificationStoreHibernateDao;
	}

	public void onClick$ref()
	{
		//System.out.println("Service_ id : " + service.getSelectedItem().getValue());
		//System.out.println("Season : " + season.getSelectedItem().getValue());
		//System.out.println("Text value : " + txt.getValue());
		
		String service_id = "10";
		String season = "0";
		String dateFrom = "";
		String dateTo = "";
		String order = "2";
		List TDRetailers = this.verificationStoreHibernateDao.getTraditionalRetailers(service_id, season, dateFrom, dateTo, order);
		
		//VerificationStoreHibernateDao storeHibernateDao = new VerificationStoreHibernateDao();
		//List TDRetailers = this.verificationStoreHibernateDao.getTraditionalRetailers(service_id);
		//ListModel listModel = this.retailers.getModel();
		ListModelList listModelList = (ListModelList) this.retailer.getModel();
		listModelList.clear();
		listModelList.addAll(TDRetailers);
		

		ListModelList listModelList1 = (ListModelList) this.retailers1.getModel();
		listModelList1.clear();
		listModelList1.addAll(TDRetailers);
		logger.info("Service Id %%%%% " );
		//this.setService_id();
	}

	public void onCreate$retailers_win(Event event) throws Exception 
	{
		String service_id = "0";
		String season = "0";
		String dateFrom = "";
		String dateTo = "";
		String order = "2";
		List TDRetailers = this.verificationStoreHibernateDao.getTraditionalRetailers(service_id, season, dateFrom, dateTo, order);
		final BindingListModelList lml = (BindingListModelList) getRetailer().getModel();
		lml.clear();
		lml.addAll(TDRetailers);
		System.out.println("created");
		
		Map<String, Object> args = getCreationArgsMap(event);
		this.setCertilogoService((CertilogoService)this.args.get("user"));

		// Bean_To_UI
		binder = (AnnotateDataBinder) event.getTarget().getVariable("binder", false);
		binder.loadAll();
		
	}

	public void onClick$ref(Event event) throws Exception 
	{
		System.out.println("Service : " +this.getService());
	}
	

	public Map<String, Object> getCreationArgsMap(Event event) {
		CreateEvent ce = (CreateEvent) ((ForwardEvent) event).getOrigin();
		return ce.getArg();
	}

	/**
	 * @param certilogoService the certilogoService to set
	 */
	public void setCertilogoService(CertilogoService certilogoService) {
		this.certilogoService = certilogoService;
	}

	/**
	 * @return the certilogoService
	 */
	public CertilogoService getCertilogoService() {
		return certilogoService;
	}

	
}

and finally my traditional_retailer.zul file is

<?xml version="1.0" encoding="UTF-8"?>
<zk xmlns="http://www.zkoss.org/2005/zul">
<style src="/css/style.css" />
<?page title="Certilogo ECC" ?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<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">
<include src="filter_bar.zul" />
	<div id="product_table" align="left" width="100%" >
             	
             			<listbox id="retailer" fixedLayout="true" model="@{controller.TDRetailers}"	>
	             			 
						  <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>
					</div>
					<button id="ref" label="Ref"></button>
</window>
</zk>


thanx for your helping nature.

link publish delete flag offensive edit

answered 2011-02-16 14:27:37 +0800

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

Please don't cross post. Look at your other thread here.

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-12-03 06:00:08 +0800

Seen: 1,146 times

Last updated: Feb 16 '11

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