Buttons"

From Documentation
m (Created page with '{{ZKDevelopersGuidePageHeader}} There are two types of buttons: <tt>button</tt> and <tt>toolbarbutton</tt>. While the looks of the buttons are different, their behaviors are the…')
 
m (correct highlight (via JWB))
 
Line 1: Line 1:
 
{{ZKDevelopersGuidePageHeader}}
 
{{ZKDevelopersGuidePageHeader}}
  
There are two types of buttons: <tt>button</tt> and <tt>toolbarbutton</tt>. While the looks of the buttons are different, their behaviors are the same. The <tt>button</tt> component uses the HTML BUTTON tag, while the <tt>toolbarbutton</tt> component uses the HTML Anchor(A) tag.
+
There are two types of buttons: <code>button</code> and <code>toolbarbutton</code>. While the looks of the buttons are different, their behaviors are the same. The <code>button</code> component uses the HTML BUTTON tag, while the <code>toolbarbutton</code> component uses the HTML Anchor(A) tag.
  
You could assign a label and an image to a button by utilizing the <tt>label</tt> and <tt>image</tt> attributes. If both are specified, the <tt>dir</tt> property controls which is displayed first, and the <tt>orient</tt> property controls whether the layout is horizontal or vertical.
+
You could assign a label and an image to a button by utilizing the <code>label</code> and <code>image</code> attributes. If both are specified, the <code>dir</code> property controls which is displayed first, and the <code>orient</code> property controls whether the layout is horizontal or vertical.
  
 
[[Image:FormAndInput_4.png]]
 
[[Image:FormAndInput_4.png]]
Line 16: Line 16:
 
</source>
 
</source>
  
In addition to employing URLs to specify images, you can dynamically assign a generated image to a button using the <tt>setImageContent</tt> method. Refer to the following section for details.
+
In addition to employing URLs to specify images, you can dynamically assign a generated image to a button using the <code>setImageContent</code> method. Refer to the following section for details.
  
'''Tip:''' The <tt>setImageContent</tt> method is supplied by all components that have an <tt>image</tt> property. Simply put, <tt>setImageContent</tt> is used for dynamically generated images, while <tt>image</tt> is used for images identifiable by a URL.
+
'''Tip:''' The <code>setImageContent</code> method is supplied by all components that have an <code>image</code> property. Simply put, <code>setImageContent</code> is used for dynamically generated images, while <code>image</code> is used for images identifiable by a URL.
  
 
=== The onClick Event and href Property ===
 
=== The onClick Event and href Property ===
There are two ways to add behavior to a <tt>button</tt> and <tt>toolbarbutton</tt>. Firstly, you can specify a listener for the <tt>onClick</tt> event. Secondly, you could specify a URL for the <tt>href</tt> property. If both are specified, the <tt>href</tt> property has the higher priority, i.e., the onClick event won't be sent.
+
There are two ways to add behavior to a <code>button</code> and <code>toolbarbutton</code>. Firstly, you can specify a listener for the <code>onClick</code> event. Secondly, you could specify a URL for the <code>href</code> property. If both are specified, the <code>href</code> property has the higher priority, i.e., the onClick event won't be sent.
  
 
<source lang="xml" >
 
<source lang="xml" >
Line 41: Line 41:
  
 
=== The sendRedirect Method of the org.zkoss.zk.ui.Execution Interface ===
 
=== The sendRedirect Method of the org.zkoss.zk.ui.Execution Interface ===
When processing an event, you can decide to stop processing the current desktop and redirect to another page by using the <tt>sendRedirect</tt> method. In other words, from the user』s viewpoint the following two buttons have exactly the same effect.
+
When processing an event, you can decide to stop processing the current desktop and redirect to another page by using the <code>sendRedirect</code> method. In other words, from the user』s viewpoint the following two buttons have exactly the same effect.
  
 
<source lang="xml" >
 
<source lang="xml" >
Line 60: Line 60:
 
</source>
 
</source>
  
Since the onClick event is sent to the server for processing, you are able to perform additional tasks before invoking <tt>sendRedirect</tt>, such as redirecting to another page only if certain conditions are satisfied.
+
Since the onClick event is sent to the server for processing, you are able to perform additional tasks before invoking <code>sendRedirect</code>, such as redirecting to another page only if certain conditions are satisfied.
  
On the other hand, the <tt>href</tt> property is processed at the client side. Your application won't be notified when users click the button.
+
On the other hand, the <code>href</code> property is processed at the client side. Your application won't be notified when users click the button.
  
 
===Button supports OS mold===
 
===Button supports OS mold===

Latest revision as of 10:41, 19 January 2022

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


There are two types of buttons: button and toolbarbutton. While the looks of the buttons are different, their behaviors are the same. The button component uses the HTML BUTTON tag, while the toolbarbutton component uses the HTML Anchor(A) tag.

You could assign a label and an image to a button by utilizing the label and image attributes. If both are specified, the dir property controls which is displayed first, and the orient property controls whether the layout is horizontal or vertical.

FormAndInput 4.png

 
<zk>
	<button label="Left" image="/img/folder.gif" width="125px"/>
	<button label="Right" image="/img/folder.gif" dir="reverse" width="125px"/>
	<button label="Above" image="/img/folder.gif" orient="vertical" width="125px"/>
	<button label="Below" image="/img/folder.gif" orient="vertical" dir="reverse" width="125px"/>
</zk>

In addition to employing URLs to specify images, you can dynamically assign a generated image to a button using the setImageContent method. Refer to the following section for details.

Tip: The setImageContent method is supplied by all components that have an image property. Simply put, setImageContent is used for dynamically generated images, while image is used for images identifiable by a URL.

The onClick Event and href Property

There are two ways to add behavior to a button and toolbarbutton. Firstly, you can specify a listener for the onClick event. Secondly, you could specify a URL for the href property. If both are specified, the href property has the higher priority, i.e., the onClick event won't be sent.

<zk>
	<window title="example">
		<zscript>
			void do_something_in_Java()
			{
				alert("hello");
				//redirect to another page
			}
		</zscript>

		<button label="click me" onClick="do_something_in_Java()"/>
		<button label="don't click that one, click me" href="/another_page.zul"/>
	</window>
</zk>

The sendRedirect Method of the org.zkoss.zk.ui.Execution Interface

When processing an event, you can decide to stop processing the current desktop and redirect to another page by using the sendRedirect method. In other words, from the user』s viewpoint the following two buttons have exactly the same effect.

<zk>
	<window>
		<zscript>
			void sendRedirect(url)
			{
				alert("sending redirect");
				//send redirect url
			}
		</zscript>
		
		<button label="redirect" onClick="sendRedirect(&quot;another.zul&quot;)"/>
		<button label="href" href="another.zul"/>
	</window>
</zk>

Since the onClick event is sent to the server for processing, you are able to perform additional tasks before invoking sendRedirect, such as redirecting to another page only if certain conditions are satisfied.

On the other hand, the href property is processed at the client side. Your application won't be notified when users click the button.

Button supports OS mold

For those who prefer native Button styling, please use the OS mold as demonstrated below:

<zk>
	<button mold="os" label="os mold"/>
</zk>


The difference lies in the generated HTM, OS molds will generate the <button> tag instead of

tags.


Last Update : 2022/01/19

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