0

How to pass parameters to new component using executions.createcomponents

asked 2010-09-07 00:53:36 +0800

enricoge gravatar image enricoge
27 1 1

I tried to create a new component passing a map but the when i get the arg map it is empty.

delete flag offensive retag edit

19 Replies

Sort by » oldest newest

answered 2012-05-09 15:18:05 +0800

saius gravatar image saius
45

Please,i've already apply a bind composer and a view model to my first zul page.so I write code java in my first zul page to call modal window.but in the composer of my modal window,how I retrieve map "arg" .in the method after compose of the link you gave me,where does come from "arg". How to instantiate it to retrieve map.

link publish delete flag offensive edit

answered 2012-05-09 21:10:13 +0800

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

arg is an implizite variable in the GenericForwardComposer class.

only snippets

public class MyModalDetailWindowCtrl extends GenericForwardComposer implements Serializable {

   . . .


	@Override
	public void doAfterCompose(Component window) throws Exception {
		super.doAfterCompose(window);

		/**
		 * Set an 'alias' for this composer name in the zul file for access.<br>
		 * Set the parameter 'recurse' to 'false' to avoid problems with
		 * managing more than one zul-file in one page. Otherwise it would be
		 * overridden and can ends in curious error messages.
		 */
		self.setAttribute("controller", this, false);

		/**
		 * 1. Get/Set the Parent/MainController and set this controller back.<br>
		 * 2. Check if their is a selected bean in the Parent/Mainmodule. If yes
		 * than get them.
		 */
		if (arg.containsKey("ModuleMainController")) {
			setSecurityGroupMainCtrl((SecurityGroupMainCtrl) arg.get("ModuleMainController"));
			// SET THIS CONTROLLER TO THE module's Parent/MainController
			getSecurityGroupMainCtrl().setSecurityGroupDetailCtrl(this);
			// GET/SET the selected bean.
			if (getSecurityGroupMainCtrl().getSelectedSecurityGroup() != null) {
				setSelectedSecurityGroup(getSecurityGroupMainCtrl().getSelectedSecurityGroup());
			}
		} else {
			setSelectedSecurityGroup(null);
		}

	}


	/**
	 * On creating the window.
	 * 
	 * @param event
	 * @throws Exception
	 */
	public void onCreate$windowSecurityGroupDetail(Event event) throws Exception {

		binder = (AnnotateDataBinder) event.getTarget().getAttribute("binder", true);

		binder.loadAll();

     windowSecurityGroupDetail.doModal();
	}

link publish delete flag offensive edit

answered 2012-05-10 12:57:20 +0800

saius gravatar image saius
45

ok my software consist helping a user to manage his acces . so i charge the users and their acces from a database.and when i click on a user on the listbox, an other listbox send me acces for this selected user. and to modify acces for the selected user i need to open a modal window to transform acces. So how to transfer acces from my master zul page to the composer of my modal window.
i send you my code:

this is my master zul page

<?page title="tableau de bord" contentType="text/html;charset=UTF-8"?>
<zk>
 
<window title="tableau de bord" border="normal" apply="org.zkoss.bind.BindComposer"  viewModel="@id('vm') @init('demo.web.ui.ctrl.UserViewModel')">
<hlayout spacing="0" height="400px">
//listbox where i charge all my users
        <listbox  vflex="true" width="401px" model="@load(vm.users)" selectedItem="@bind(vm.selectedUser)">
            <auxhead>
                <auxheader colspan="3" class="topic">Liste des personnes</auxheader>
            </auxhead>
            <listhead>
                <listheader label="Nom" width="80px" align="center" />
                <listheader label="Prenom" align="center" />
                <listheader label="Email" width="80px" align="center" />
            </listhead>
            <template name="model" var="user">
                <listitem>
                    <listcell label="@load(user.firstName)" />
                    <listcell label="@load(user.lastName)" />
                    <listcell label="@load(user.mail)" />
                    

            
                </listitem>
            </template>
 
        </listbox>
        <window>
//list box where i charge "acces" for selected user in  the first listbox
 <listbox width="800px" model="@load(vm.selectedUser.acces)" id="ac">
  <auxhead>
                <auxheader colspan="3" class="topic">Liste des personnes</auxheader>
            </auxhead>
		<listhead>
			<listheader label=""/>
			<listheader label="Nom"/>
			<listheader label="Description"/>
			<listheader label="Ville"/>
			<listheader label="Rue"/>
			<listheader label="Code postal"/>
			<listheader label="Creer autorisations"/>		
		</listhead>
		<template name="model" var="acces">

			<listitem>
			
			<listcell label=""/>
            <listcell label="@load(acces.nom)"/>
            <listcell label="@load(acces.description)"/>
            <listcell label="@load(acces.rue)"/>
            <listcell label="@load(acces.ville)"/>
            <listcell label="@load(acces.codePostal)"/>
           <listcell>
            <button id="btn" label="Créer" >
            //i want retrieve "acces" from selected user to send it in the composer of my modal window
             <attribute name="onClick" ><![CDATA[
Map arg = new HashMap();
arg.put("acc",ac.getSelectedItem());
Executions.createComponents("CreationAutorisation.zul", null, arg);
creaAuto.doModal();

        ]]></attribute>
            </button>
           </listcell>
            
        </listitem>
       
        </template>
		
	</listbox>
  </window>
  </hlayout>
  
</window>

</zk>

this is the controller ('demo.web.ui.ctrl.UserViewModel') for my master zu page:

package demo.web.ui.ctrl;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;

import javax.validation.ConstraintViolation;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zkoss.bind.annotation.Init;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.GlobalCommand;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zkplus.databind.BindingValidateEvent;
import org.zkoss.zul.Label;

import demo.model.DAOs;
import demo.model.UserDAO;

import demo.model.bean.User;

import demo.web.ui.ctrl.Validations.ViolationRunner;

/**
 * @author   virgil
 */
public class UserViewModel extends GenericForwardComposer {

private List<User> users=new ArrayList<User>((DAOs.getUserDAO().findAll()));

...
}



this is my modal window zul page

<?page title="créer une autorisation" contentType="text/html;charset=UTF-8"?>
<zk>
<window id="creaAuto" visible="false" title="Créer une autorisation" closable="true" border="none"  width="600px"  apply="demo.web.ui.ctrl.EnregistrerAutorisationsCtrl">
 <zscript><![CDATA[
        List essai = (new demo.web.ui.ctrl.UserViewModel()).getUsers();
       
    ]]></zscript>
<grid>
		<columns>
			<column label="type"/>
			<column label="content"/>
		</columns>
		<rows>
			<row>	
				<label value="Nom" />
				<textbox id="nameAutorisation"/>
			</row>
			<row>	
				<label value="description" />
				<textbox id="intro" rows="6"/>
			</row>
			<row>	
					<label value="debut" />
					<hbox>
					 <datebox id="dateDebut" cols="16" format="long+medium" onCreate="self.value = new Date()"  />
				</hbox>
			</row>
			<row>	
					<label value="fin" />
				<hbox>
					<datebox id="dateFin" cols="16" format="long+medium" onCreate="self.value = new Date()"  />
				</hbox>
			</row>
			<row>
			<label value="Personne" />
			 <bandbox id="pers"  autodrop="true"> 
        <bandpopup>
        <listbox  id="guests" vflex="true" height="250px" width="401px"  
                 mold="paging" autopaging="true" onSelect="pers.value=self.selectedItem.label; pers.close();">
            <auxhead>
                <auxheader colspan="3" class="topic">Liste des personnes</auxheader>
            </auxhead>
            <listhead>
                <listheader label="Nom" width="80px" align="center" />
                <listheader label="Prenom" align="center" />
                <listheader label="Email" width="80px" align="center" />
            </listhead>
            
                <listitem forEach="${essai}">
                    <listcell label="${each.firstName}" />
                    <listcell label="${each.lastName}" />
                    <listcell label="${each.mail}" />
                </listitem>
            
 		</listbox>
        </bandpopup>
    </bandbox>
			</row>
			 <row>
                <cell colspan="3" style="text-align:center">
                    <button id="submit" label="Valider" width="100px" height="30px"/>                  
                       

                </cell>
            </row>
		</rows>
	</grid>
</window>
</zk>

So, i don't know how to write the composer of my modal window to retrieve "selectedUser.acces" from the listbox of my master zul page

I'm new to zk!

thanks

link publish delete flag offensive edit

answered 2012-05-10 13:06:18 +0800

Matze2 gravatar image Matze2
773 7

updated 2012-05-10 13:06:58 +0800

I suppose EnregistrerAutorisationsCtrl extends GenericForwardComposer. In this case you have access to protected variable arg which looks the same as your arg Map in createComponents() call.
The best place to access arg is in doAfterCompose(). Stephan's sample show exactly that.

Side note: I am not sure, if you fully understood the different controller concepts available in ZK.
There is the ZK5 composer concept, where you write a so-called composer usually extended from GenericForwardComposer.
And there is the ZK6 MVVM concept. Here your composer is fixed (BindComposer) and you write a view model which is a POJO. But you extend from GenericForwardComposer, too, which makes no sense for ViewModel.

Do not mix the technologies if you are new.

link publish delete flag offensive edit

answered 2012-05-10 20:19:40 +0800

saius gravatar image saius
45

updated 2012-05-10 20:21:22 +0800

Ok,I tried .arg.containkey return TRUE but the object

link publish delete flag offensive edit

answered 2012-08-01 13:57:01 +0800

kidleo gravatar image kidleo
81 1

Hi,

Considering the following case:

<window id="winView" title="View" border="normal" use="DispatcherView">
.....
<div apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('myModel')" height="100%">

...
</window>

it's possible call myModel using some parameter (for istance p) defined and istantiated in the DispatcherView class (not necessarily using MyModel costructor as in the following pseudo codice)

class DispatcherView extends Window
{
Person p;
....
}


class MyModel {
Person p;
....
public MyModel(Person p){
this.p=p;
}

.....
}
THK.

link publish delete flag offensive edit

answered 2012-08-01 16:33:38 +0800

kidleo gravatar image kidleo
81 1

To be more detailed I need to create a component (grid) directly

using createComponentsDirectly(java.lang.String content, java.lang.String extension, Component parent, java.util.Map<?,?> arg)

I would like to passing at this compontes data and get it inside a BinderComposer (for Istance myModel)

In another context I used createComponents(java.lang.String uri, Component parent, java.util.Map<?,?> arg) and workfine.

At the ends my problem is: I can i pass parameters to myModel using createComponentsDirectly?

link publish delete flag offensive edit

answered 2012-08-06 01:19:05 +0800

samchuang gravatar image samchuang
4084 4

you can use @Init and use Parameters

link publish delete flag offensive edit

answered 2012-12-27 06:43:22 +0800

zknl gravatar image zknl
124 2

Hello everyone
Stephen sir i am just dealing with two zuls(parent and child windows) i am not using any data binding as its not needed as well as not used any composer
i have posted my problem under thread"window domodal problem plz help" please read it and tell me how do i get back the groupbox from modal window to
parent window in zul coding itself.(no any composer i have used)
i had tried with your suggestion like
if (arg.containsKey("gb_details")) {
alert("ok");
}else alert("else");
but of no use ...

please do help
Regards,
Nil

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-09-07 00:53:36 +0800

Seen: 4,872 times

Last updated: Dec 27 '12

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