Messagebox"

From Documentation
m
Line 12: Line 12:
  
 
It is typically used to alert users when an error occurs, or to prompt user for an decision.  
 
It is typically used to alert users when an error occurs, or to prompt user for an decision.  
 +
 +
 +
Note: it will have different behavior between you enable EventThread or not. (Refer to [[ZK_Configuration_Reference/zk.xml/The_system-config_Element/The_disable-event-thread_Element|The_disable-event-thread_Element]] )
 +
*When you enable event thread , it will work like a modal window .(It will pause current thread and waiting it to continue.)
 +
* If you do customization on messagebox , you might need to know that the z-class on mesasge window would be different ,too.
  
  
 
= Example =
 
= Example =
  
 +
 +
* In EventThread disable enviroment (default case)
 
<source lang="xml" >
 
<source lang="xml" >
 
<window title="Messagebox demo" border="normal">
 
<window title="Messagebox demo" border="normal">
 
<button label="Question" width="100px">
 
<button label="Question" width="100px">
<attribute name="onClick">{ Messagebox.show("Question is pressed. Are
+
<attribute name="onClick">
you sure?", "Question", Messagebox.OK | Messagebox.CANCEL,
+
//in disable case .
Messagebox.QUESTION); }</attribute>
+
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("onOK".equals(e.getName())){
 +
alert("user click ok ");
 +
}else if("onCancel".equals(e.getName())){
 +
alert("user click cancel ");
 +
}
 +
 +
/* Event Name Mapping list
 +
Messagebox.YES = "onYes";
 +
Messagebox.NO  = "onNo";
 +
Messagebox.RETRY = "onRetry";
 +
Messagebox.ABORT = "onAbort";
 +
Messagebox.IGNORE = "onIgnore";
 +
Messagebox.CANCEL = "onCancel";
 +
Messagebox.OK = "onOK";
 +
*/
 +
 +
}
 +
}
 +
);
 +
</attribute>
 
</button>
 
</button>
 
</window>
 
</window>
Line 27: Line 58:
  
  
 +
* In EventThread enable enviroment
 +
 +
<source lang="xml" >
 +
<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>
 +
</source>
  
 
=Customization=
 
=Customization=
Line 62: Line 113:
  
 
=Use cases=
 
=Use cases=
 +
  
 
{| border='1px' | width="100%"
 
{| border='1px' | width="100%"

Revision as of 01:41, 9 February 2011

Messagebox

Employment/Purpose

It provides a set of utilities to show message boxes.

It is typically used to alert users when an error occurs, or to prompt user for an decision.


Note: it will have different behavior between you enable EventThread or not. (Refer to The_disable-event-thread_Element )

  • When you enable event thread , it will work like a modal window .(It will pause current thread and waiting it to continue.)
  • If you do customization on messagebox , you might need to know that the z-class on mesasge window would be different ,too.


Example

  • In EventThread disable enviroment (default case)
<window title="Messagebox demo" border="normal">
	<button label="Question" width="100px">
		<attribute name="onClick">
	//in disable case . 
	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("onOK".equals(e.getName())){
	 				alert("user click ok ");
	 			}else if("onCancel".equals(e.getName())){
	 				alert("user click cancel ");
	 			}
	 			
	 			/* Event Name Mapping list
				Messagebox.YES = "onYes";
				Messagebox.NO  = "onNo";
				Messagebox.RETRY = "onRetry";
				Messagebox.ABORT = "onAbort";
				Messagebox.IGNORE = "onIgnore";
				Messagebox.CANCEL = "onCancel";
				Messagebox.OK = "onOK";
	 			*/
	 			
	 		}
	 	}
	);
</attribute>
	</button>
</window>


  • In EventThread enable enviroment
<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, 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 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

Name
Event Type
None None

Supported Children

*NONE

Use cases

Version Description Example Location
     

Version History

Version Date Content
     



Last Update : 2011/02/09

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