Difference between revisions of "Message Box"

From Documentation
m
m (correct highlight (via JWB))
 
Line 6: Line 6:
  
 
== The Message Box ==
 
== The Message Box ==
The <tt>org.zkoss.zul.Messagebox</tt> class provides a set of utilities to show message boxes. It is typically used to alert user when an error occurs, or to prompt user for an decision.
+
The <code>org.zkoss.zul.Messagebox</code> class provides a set of utilities to show message boxes. It is typically used to alert user when an error occurs, or to prompt user for an decision.
  
 
<source lang="java" >
 
<source lang="java" >
Line 14: Line 14:
 
</source>
 
</source>
  
Since it is common to alert user for an error, a global function called <tt>alert</tt> is added for zscript. The <tt>alert</tt> function is a shortcut of the <tt>show</tt> method in the <tt>Messagebox</tt> class. In other words, The following two statements are equivalent.
+
Since it is common to alert user for an error, a global function called <code>alert</code> is added for zscript. The <code>alert</code> function is a shortcut of the <code>show</code> method in the <code>Messagebox</code> class. In other words, The following two statements are equivalent.
  
 
<source lang="java" >
 
<source lang="java" >
Line 21: Line 21:
 
</source>
 
</source>
  
Notice that <tt>Messagebox</tt> is a modal window so it shares the same constraint: executable only in an event listener. Thus, the following codes will fail. Refer to the '''Modal Windows and Event Listeners''' section above for more descriptions.
+
Notice that <code>Messagebox</code> is a modal window so it shares the same constraint: executable only in an event listener. Thus, the following codes will fail. Refer to the '''Modal Windows and Event Listeners''' section above for more descriptions.
  
 
<source lang="xml" >
 
<source lang="xml" >

Latest revision as of 02:58, 20 January 2022

Documentationessage Box
essage Box


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


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

The Message Box

The org.zkoss.zul.Messagebox class provides a set of utilities to show message boxes. It is typically used to alert user when an error occurs, or to prompt user for an decision.

if (Messagebox.show("Remove this file?", "Remove?", Messagebox.YES | Messagebox.NO, Messagebox.QUESTION) ==  Messagebox.YES) {
 ...//remove the file
}

Since it is common to alert user for an error, a global function called alert is added for zscript. The alert function is a shortcut of the show method in the Messagebox class. In other words, The following two statements are equivalent.

alert("Wrong");
Messagebox.show("Wrong");

Notice that Messagebox is a modal window so it shares the same constraint: executable only in an event listener. Thus, the following codes will fail. Refer to the Modal Windows and Event Listeners section above for more descriptions.

<window title="Messagebox not allowed in paging loading">
    <zscript>
		//failed since show cannot be called in paging loading
		if (Messagebox.show("Redirect?", "Redirect?",
		Messagebox.YES | Messagebox.NO, Messagebox.QUESTION) == Messagebox.YES)
			Executions.sendRedirect("another.zul");
    </zscript>
</window>



Last Update : 2022/01/20

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