Modal Windows"

From Documentation
Line 4: Line 4:
  
 
=== Modal Windows ===
 
=== Modal Windows ===
You can not use the modal window anymore. You can create the same visual effect with the highlighted mode. However, at the server side, it works just like the overlapped mode – it returns immediately without waiting for user's response.
+
 
 +
Since the event is processed in the Servlet thread, the execution cannot be suspended. Thus, the modal window behaves the same as the highlited window. At the client side, the visual effect is the same: a semi-transparent mask blocks the end user from access components other than the modal window. However, at the server side, it works just like the overlapped mode – it returns immediately without waiting for user's closing the window.
  
 
<source lang="java" >
 
<source lang="java" >
 
  win.doHighlighted(); //returns once the mode is changed; not suspended
 
  win.doHighlighted(); //returns once the mode is changed; not suspended
 +
System.out.println("next");
 
</source>
 
</source>
+
 
 +
The "next" message will be printed to the console before the end user closes the modal window.
 +
 
 
=== Message Boxes ===
 
=== Message Boxes ===
 
The message boxes returns immediately so it always returns <tt>Messagebox.OK</tt>. Thus, it is meaningless to show buttons other than the OK button. For example, the <tt>if</tt> clause in the following example is never true.
 
The message boxes returns immediately so it always returns <tt>Messagebox.OK</tt>. Thus, it is meaningless to show buttons other than the OK button. For example, the <tt>if</tt> clause in the following example is never true.

Revision as of 04:07, 3 September 2010

Stop.png This documentation is for an older version of ZK. For the latest one, please click here.


This section describes the notes when using the Servlet thread to process the event (the default).

Modal Windows

Since the event is processed in the Servlet thread, the execution cannot be suspended. Thus, the modal window behaves the same as the highlited window. At the client side, the visual effect is the same: a semi-transparent mask blocks the end user from access components other than the modal window. However, at the server side, it works just like the overlapped mode – it returns immediately without waiting for user's closing the window.

 win.doHighlighted(); //returns once the mode is changed; not suspended
 System.out.println("next");

The "next" message will be printed to the console before the end user closes the modal window.

Message Boxes

The message boxes returns immediately so it always returns Messagebox.OK. Thus, it is meaningless to show buttons other than the OK button. For example, the if clause in the following example is never true.

 if (Messagebox.show("Delete?", "Prompt", Messagebox.YES|Messagebox.NO,
     Messagebox.QUESTION) == Messagebox.YES) {
     this_never_executes();
 }

Rather, you have to provide an event listener as follows.

 Messagebox.show("Delete?", "Prompt", Messagebox.YES|Messagebox.NO,
     Messagebox.QUESTION,
     new EventListener() {
         public void onEvent(Event evt) {
             switch (((Integer)evt.getData()).intValue()) {
             case Messagebox.YES: doYes(); break; //the Yes button is pressed
             case Messagebox.NO: doNo(); break; //the No button is pressed
             }
         }
     }
 );

The event listener you provided is invoked when the user clicks one of the buttons. Then, you can identify which button is clicked by examining the data (Event's getData). The data is an integer whose value is the button's identifier, such as Messagebox.YES.

Alternatively, you can examine the event name:

 public void onEvent(Event evt) {
     if ("onYes".equals(evt.getName())) {
         doYes(); //the Yes button is pressed
     } else if ("onNo".equals(evt.getName())) {
         doNo(); //the No button is pressed
     }
 }

Note: The event name for the OK button is onOK, not onOk.

File Upload

The file upload dialog is no longer applicable. Rather, you shall use Button or Toolbarbutton with upload="true" instead. For example,

<zk>
	<zscript>
	void upload(Event event) {
		org.zkoss.util.media.Media media = event.getMedia();
		if (media instanceof org.zkoss.image.Image) {
			org.zkoss.zul.Image image = new org.zkoss.zul.Image();
			image.setContent(media);
			image.setParent(pics);
		} else {
			Messagebox.show("Not an image: "+media, "Error", Messagebox.OK, Messagebox.ERROR);
			break; //not to show too many errors
		}
	}
	</zscript>
	<button label="Upload" upload="true" onUpload="upload(event)"/>
	<toolbarbutton label="Upload" upload="true" onUpload="upload(event)"/>
	<vbox id="pics" />
</zk>

If you prefer to use a dialog (Fileupload.get()), please take a look at ZK Component Reference: Fileupload for more inormation.


Last Update : 2010/09/03

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.