-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have a need to pop-up a modal dialog box within my Java listener method. What i want to do is create a zul file that defines the modal dialog and its labels, text fields, then call that zul file from within the listener method of my Java class. Once the end-user adds information in the modal dialog and hits the 'enter' button I will capture the data from the modal dialog's text fields and move to the next step.
I have googled every combination of "execute/call zul file from within java" that i can think of with no results. Is there a way (I got to think there is). I would hate to think that I have to dynamically create the modal window from within my java code.
Any help is appreciated....thanks
Hi clueless
I create a sample
index.zul
<zk> <window apply="ctrl.Composer"> <div id="div" /> <button label="dialog" id="btn" /> </window> </zk>
Composer.java
package ctrl; import java.util.*; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.util.GenericForwardComposer; import org.zkoss.zul.Div; public class Composer extends GenericForwardComposer { private Div div; public void onClick$btn(){ User jimmy = new User("Jimmy", 26); Map data = new HashMap(); data.put("name", jimmy.getName()); data.put("age", jimmy.getAge()); Executions.createComponents("dialog.zul", div, data); } public class User{ private String name; private int age; public User(String name, int age) { super(); this.name = name; this.age = age; } public String getName() { return name; } public int getAge() { return age; } } }
dialog.zul
<window title="User" border="normal" mode="modal"> <label value="Name:" /> <textbox value="${arg.name}"/> <separator/> <label value="Age:" /> <intbox value="${arg.age}"/> </window>
as1225 - thanks for your reply. The issue I'm facing with your solution is that I lose the instance of the Composer I am calling Executions.createComponent(...) from. I believe the reason for this is because in your index.zul the apply=ctrl.Composer creates a new instance of ctrl.Composer. In my case I have the following desired effect:
ctrl.Composer calls Executions.createComponent("myDialog",,). Inside 'myDialog' there is information the user fills out and then a 'ok button' to complete the dialog. What i need is for the ctrl.Composer that called Executions.createComponent("myDialog",,) to receive the onClick$btn event and not a new instance of ctrl.Composer.
I modify my demo to receive data
index.zul
<zk> <window apply="ctrl.Composer"> <label value="Name:"/> <label id="nameLb"/> <separator/> <label value="Age:"/> <label id="ageLb"/> <div id="div" /> <button label="dialog" id="btn" /> </window> </zk>
ctrl.Composer.java
package ctrl; import java.util.*; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.util.GenericForwardComposer; import org.zkoss.zkplus.databind.AnnotateDataBinder; import org.zkoss.zul.*; public class Composer extends GenericForwardComposer { private Div div; private Label nameLb; private Label ageLb; private User user; private AnnotateDataBinder binder; public void onClick$btn(){ final User jimmy = new User("Jimmy", 26); Map data = new HashMap(); data.put("user", jimmy); Window dialogWin = (Window) Executions.createComponents("dialog.zul", div, data); binder = new AnnotateDataBinder(dialogWin); binder.loadAll(); dialogWin.addEventListener("onClose", new EventListener() { @Override public void onEvent(Event event) throws Exception { nameLb.setValue(jimmy.getName()); ageLb.setValue(jimmy.getAge() + ""); } }); } public class User{ private String name; private int age; public User(String name, int age) { super(); this.name = name; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } } }
dialog.zul
<window id="dialogWin" title="User" border="normal" mode="modal"> <zscript><![CDATA[ import ctrl.Composer.User; User user = (User)execution.getArg().get("user"); ]]></zscript> <label value="Name:" /> <textbox id="nameTb" value="@{user.name}"/> <separator/> <label value="Age:" /> <intbox id="ageIb" value="@{user.age}"/> <button label="OK" xmlns:w="http://www.zkoss.org/2005/zk/client" w:onClick="this.$f('dialogWin').fire('onClose');"/> </window>
as1225 - thanks again for the reply. Here is my situation:
First, i am using groovy and not 1.7 (not supported in my IDE) so anonymous inner classes aren't supported. Yes, i can use Java, but that somewhat defeats the purpose.
Second, what I am doing is adding user entered data to a node when it is dropped. Once I receive the data I need to determine where the node is going to be placed and may need to alter the position of other nodes. I need to stay in the component (Panel) that I launch the dialog from.
In an older use of ZK there was a way to do a method callback from within the .zul file. In 5.0.2 is this still possible??
thanks again for all of your help, it is greatly appreciated!!!!
or, any other solution that may work. I can't see any solution where i am leaving the Composer Instance that calls the dialog.zul. It seems that this should have a simple solution since the behavior of dialogs is to get data and return to the calling parent.
so the question I need help resolving:
Is there a way that will allow me to call a dialog from a Composer instance and return to the same composer instance with the information captured in the dialog window?
so you don't want using javaBean to receive data ?
@clueless,
Is there a way that will allow me to call a dialog from a Composer instance and return to the same composer instance with the information captured in the dialog window?
I do work in such a case all times in the Zksample2. Look at the codes. By calling a DialogWindow i overhanded the parent composer self as a param to the DialogWindow in the Executions.createCompo...('zulDialog.zul' ,parent, paramMap). So i can in the onCreate() methode of the Dialog read back the parent Composer instance. Now i have in the Dialog full control of the parent composer.
best
Stephan
Hello ,
Here, in the above example from index.zul we are starting .......
but my requirement is controll starts from the java program......
I am giving my code.......
MY java program is:
GPSTruckTrackingFunctionality.java
import org.adempiere.webui.panel.ADForm;
import org.zkoss.zk.ui.Executions;
public class GPSTruckTrackingSystem extends ADForm implements EventListener
{
public Iframe iframe;
public AnnotateDataBinder binder=null;
public Include incl;
public GPSTruckTrackingSystem()
{
/************if this is the case it is working fine****************************/
iframe=new Iframe();
iframe.setHeight("100%");
iframe.setWidth("100%");
iframe.setSrc("./zul/GPSTruckTrackingSystem.zul");
this.appendChild(iframe);
/*********************but i am restricted to use iframe*************************************/
/************************so i go for**********************************************************/
Include incl=new Include();
incl.setHeight("100%");
incl.setWidth("100%");
incl.setSrc("./zul/GPSTruckTrackingSystem.zul");
this.appendChild(incl);
/***it is also working (But at first it is showing blank browser -- after i click on URL in bowser and press enter it is appearing)***********/
/****************i have tried in another way**************************************/
try
{
Window win=(Window)Executions.createComponents("./zul/GPSTruckTrackingSystem.zul",null,null);
binder = new AnnotateDataBinder(win);
binder.loadAll();
//this.appendChild(win);
}
catch(Exception ex)
{
System.out.println("iframe:exception"+ex.toString());
}
/***********in this case also first browser is showing empty page ,after clicking on the URL the actual window is appearing********************/
I can't extend GenericForwardComposer
i have to extend ADform (other wise i can't access this form)
and My Zul file is:
GPSTruckTrackingSystem.zul:
<zk>
<window id="win_gps" use="org.adempiere.webui.window.GPSTruckTrackingFunctionality">
<borderlayout id="border" height="600px" >
<west title="TrackVehicle" size="35%" flex="true" maxsize="250" splittable="true" collapsible="true">
<borderlayout>
<north size="30%" height="120px" border="none" flex="true" splittable="true" collapsible="true">
<groupbox mold="3d" width="100%">
<caption label="TruckOperations"/>
<grid>
<rows>
<row>
<label value="TruckName:"/>
<textbox id="texttruck"/>
</row>
</rows>
</grid>
<grid>
<rows>
<row>
<button id="btrace" label="TRACE" width="50px" height="20px" onClick="win_gps.traceTruck()"/>
<button id="bfind" label="Find" width="50px" height="20px" onClick="win_gps.findVehicle()"/>
<button id="bRefresh" label="REFRESH" width="50px" height="20px" onClick="win_gps.reFresh()"/>
<button id="bAdd" label="ADD" width="50px" height="20px">
<attribute name="onClick">
<![CDATA[
Window Addtruck = (Window) Executions.createComponents("AddTruck.zul",null,null);
try
{
Addtruck.doModal();
}
catch (Exception e)
{
}
]]>
</attribute>
</button>
</row>
</rows>
</grid>
</groupbox>
</north>
<center id="checkbox" border="none" flex="true" autoscroll="true">
<groupbox id="checkgroup" mold="3d" width="100%">
<caption label="TruckInformation"/>
<grid>
<rows id="checkboxrows">
</rows>
</grid>
</groupbox>
</center>
</borderlayout>
</west>
</borderlayout>
</window>
</zk>
Please help me.................
Regards ,
Arunkumar9
Is there another way to get my zul file into form --at the first time itself (that is without clicking on the browser URL again)
Asked: 2010-06-06 16:39:11 +0800
Seen: 3,414 times
Last updated: Jun 25 '12