Messagebox"
Line 15: | Line 15: | ||
= Example = | = Example = | ||
− | == Event Thread Disabled == | + | == Event Thread Disabled (default) == |
− | Here is an example used if [[ZK Developer's Reference/UI Patterns/Event Threads|the event thread is disabled]] (default case) | + | Here is an example used if [[ZK Developer's Reference/UI Patterns/Event Threads|the event thread is disabled]] (default case). The invocation of <javadoc method="show(java.lang.String, java.lang.String, int, java.lang.String)">org.zkoss.zul.Messagebox</javadoc> will return immediately after the invocation. To know which button is clicked, you have to implement a listener as follows. If you don't need to know which button is clicked, you could simply pass <tt>null</tt>. |
− | <source lang=" | + | <source lang="java" > |
− | + | Messagebox.show("Question is pressed. Are you sure?", | |
− | |||
− | |||
− | |||
− | |||
"Question", Messagebox.OK | Messagebox.CANCEL, | "Question", Messagebox.OK | Messagebox.CANCEL, | ||
Messagebox.QUESTION, | Messagebox.QUESTION, | ||
Line 36: | Line 32: | ||
} | } | ||
); | ); | ||
− | |||
− | |||
− | |||
</source> | </source> | ||
* Notice that, if you want to make it running under clustering environment, you should implement <javadoc type="interface">org.zkoss.zk.ui.event.SerializableEventListener</javadoc>. For more information, please refer to [[ZK Developer's Reference/Clustering/Programming Tips|ZK Developer's Reference: Clustering]]. | * Notice that, if you want to make it running under clustering environment, you should implement <javadoc type="interface">org.zkoss.zk.ui.event.SerializableEventListener</javadoc>. For more information, please refer to [[ZK Developer's Reference/Clustering/Programming Tips|ZK Developer's Reference: Clustering]]. | ||
+ | |||
+ | === Listening to ClickEvent === | ||
== Event Thread Enabled == | == Event Thread Enabled == |
Revision as of 07:44, 13 October 2011
Messagebox
- Demonstration: Messagebox
- Java API: Messagebox
- JavaScript API: N/A
Employment/Purpose
It provides a set of utilities to show a message and have a user to confirm a situation.
It is typically used to alert users when an error occurs, or to prompt users for an decision.
Example
Event Thread Disabled (default)
Here is an example used if the event thread is disabled (default case). The invocation of Messagebox.show(String, String, int, String) will return immediately after the invocation. To know which button is clicked, you have to implement a listener as follows. If you don't need to know which button is clicked, you could simply pass null.
Messagebox.show("Question is pressed. Are you sure?",
"Question", Messagebox.OK | Messagebox.CANCEL,
Messagebox.QUESTION,
new org.zkoss.zk.ui.event.EventListener(){
public void onEvent(Event e){
if(Messagebox.ON_OK.equals(e.getName())){
alert("user click ok ");
}else if(Messagebox.ON_CANCEL.equals(e.getName())){
alert("user click cancel ");
}
}
}
);
- Notice that, if you want to make it running under clustering environment, you should implement SerializableEventListener. For more information, please refer to ZK Developer's Reference: Clustering.
Listening to ClickEvent
Event Thread Enabled
Here is an example used if the event thread is enabled.
<window title="Messagebox demo" border="normal">
<button label="Question" width="100px">
<attribute name="onClick">
//in enable case .
int responseCode = Messagebox.show("Question is pressed. Are you sure?",
"Question", Messagebox.OK | Messagebox.CANCEL,
Messagebox.QUESTION);
if(responseCode == Messagebox.OK){
alert("user click ok");
}else if(responseCode == Messagebox.CANCEL){
alert("user click cancel");
}
</attribute>
</button>
</window>
Customization
The Default Title
If the title is not specified in the application's name (returned by WebApp.getAppName()). You could change it by invoking WebApp.setAppName(String).
Since 5.0.6, you could specify the application's name with a library property called org.zkoss.zk.ui.WebApp.name. For example, you could specify the following in WEB-INF/zk.xml:
<library-property>
<name>org.zkoss.zk.ui.WebApp.name</name>
<value>My Killer Application</value>
</library-property>
The Template
The UI of a message box is based on a ZUL file, so you could customize it by replacing it with your own implementation. It can be done easily by invoking Messagebox.setTemplate(String). Notice that it affects all message boxes used in an application. It is typically called when the application starts (i.e., in WebAppInit.init(WebApp) -- for more information, please refer to ZK Developer's Reference: Init and Cleanup).
To implement a custom template, please take a look at the default template.
Supported events
None | None |
Supported Children
*NONE
Use cases
Version | Description | Example Location |
---|---|---|
Version History
Version | Date | Content |
---|---|---|
6.0.0 | October 2011 | The order and labels of the buttons were assignable. |
6.0.0 | October 2011 | Messagebox.ClickEvent was introduced to simplify the identification of a button. |