-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I tried to create a new component passing a map but the when i get the arg map it is empty.
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.
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(); }
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
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.
Ok,I tried .arg.containkey return TRUE but the object
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.
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?
you can use @Init and use Parameters
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
Asked: 2010-09-07 00:53:36 +0800
Seen: 4,872 times
Last updated: Dec 27 '12