0

Messagebox.show always return value 1, irrespective of the selection button

asked 2009-10-05 13:17:15 +0800

baskaraninfo gravatar image baskaraninfo
536 2 2 9

Messagebox.show always return value 1, irrespective of the selection button.
The following is the test code in 3.6.2 version:

try {
				if (Messagebox.CANCEL == Messagebox.show("Question is pressed. Are you sure?", "Question",
						Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION)) {
					System.out.println("Messagebox.CANCEL selected!");
					return;
				} else {
					System.out.println("Messagebox.OK selected!");
					return;
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}

Thanks.

delete flag offensive retag edit

33 Replies

Sort by ยป oldest newest

answered 2009-10-05 14:05:25 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-10-05 14:10:49 +0800

Hmmmmmmmm, i have tested your code in 3.6.3 FL . All is well.

Sure you have the org.zkoss.zul.Messagebox ?
The return values for 3.6.2 and 3.6.3 are equal.

Stephan

link publish delete flag offensive edit

answered 2009-10-05 14:24:07 +0800

mjablonski gravatar image mjablonski
1284 3 5
http://www.jease.org/

updated 2009-10-05 14:24:34 +0800

Sounds like the event-thread is disabled in your application, so MessageBox does always return true:

http://docs.zkoss.org/wiki/Performance_tip#Use_the_Servlet_Thread_to_Process_Events

-Maik

link publish delete flag offensive edit

answered 2009-10-06 06:10:49 +0800

baskaraninfo gravatar image baskaraninfo
536 2 2 9

Thanks mjablonski & terrytornado.

I have not disabled the event processing thread as referred in your previous post in zk.xml. Eventhough Messagebox.OK is returned always without even waiting for the user selection.

What is the default behaviour of the zk? How can I enable event thread processing?

Thanks.

link publish delete flag offensive edit

answered 2009-10-06 10:23:15 +0800

baskaraninfo gravatar image baskaraninfo
536 2 2 9

I have found the way to enable event thread from here

<system-config>
	<disable-event-thread>false</disable-event-thread>
</system-config>

Thanks.

link publish delete flag offensive edit

answered 2009-10-07 06:44:06 +0800

baskaraninfo gravatar image baskaraninfo
536 2 2 9

The above posted code doesn't help in 3.6.2 version. It may be work only from zk 5 version.

How can I enable event thread processing in 3.6.2?

Note: I have not disabled the event processing thread in zk.xml.

link publish delete flag offensive edit

answered 2009-10-07 07:14:12 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Hi,baskaraninfo
I try on my ZK 3.6.2
it is work well

index.zul

<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
	<window apply="ctrl.Composer">
		<button id="btn" label="ok"/>
	</window>
</zk>

Composer.java

package ctrl;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.*;

public class Composer extends GenericForwardComposer {

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
	}

	public void onClick$btn() {
		try {
			if (Messagebox.CANCEL == Messagebox.show( "Question is pressed. Are you sure?", "Question",
					Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION)) {
				System.out.println("Messagebox.CANCEL selected!");
				return;
			} else {
				System.out.println("Messagebox.OK selected!");
				return;
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

}

//jimmy

link publish delete flag offensive edit

answered 2009-10-07 07:47:48 +0800

baskaraninfo gravatar image baskaraninfo
536 2 2 9

Thank you, Jimmy :)

I have tested your code and found the following result:

1, I have clicked on "ok" button and then the popup message shown.
2, Immediately it displays "Messagebox.OK selected!", eventhough I have not yet selected any options.
3, I have noticed that, the control is not waiting until we select an option in the popup window
4, I want to do some processing based on the user action. Presently, it always returns Messagebox.OK

I have also referred this link:
http://docs.zkoss.org/wiki/Performance_tip#Use_the_Servlet_Thread_to_Process_Events

But, can't able to solve this problem.

I may be missing/messed-up with some configuration setup.

My zk.xml file content:

<?xml version="1.0" encoding="UTF-8"?>
<zk>
	<device-config>
		<device-type>ajax</device-type>
		<timeout-uri>/timeout.zul</timeout-uri>
	</device-config>
	<library-property>
		<name>org.zkoss.zul.include.mode</name>
		<value>auto</value>
	</library-property>
	<language-config>
		<addon-uri>/WEB-INF/lang-addon.xml</addon-uri>
	</language-config>
</zk>

My lang-addon.xml content:

<?xml version="1.0" encoding="UTF-8"?>
<lang-addon>
	<language-name>xul/html</language-name>
	<library-property>
		<name>org.zkoss.zul.theme.fontSizeM
		</name>
		<value>11px</value>
	</library-property>
	<library-property>
		<name>org.zkoss.zul.theme.fontSizeS
		</name>
		<value>10px</value>
	</library-property>
	<library-property>
		<name>org.zkoss.zul.theme.fontSizeXS
		</name>
		<value>9px</value>
	</library-property>
	<component>
        <component-name>doublebox</component-name>
        <extends>doublebox</extends>
        <property>
            <property-name>format</property-name>
            <property-value>########0.00</property-value>
        </property>
    </component>
    <component>
        <component-name>datebox</component-name>
        <extends>datebox</extends>
        <property>
            <property-name>format</property-name>
            <property-value>MMM d, yyyy</property-value>
        </property>
    </component>
</lang-addon>

My web.xml file content:

<?xml version="1.0" encoding="UTF-8"?>

<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	<display-name>ZkBirtIntegration</display-name>

	<context-param>
		<param-name>BIRT_VIEWER_LOCALE</param-name>
		<param-value>en-US</param-value>
	</context-param>

	<!-- 
		Default timezone setting.
		Examples: "Europe/Paris", "GMT+1".
		Defaults to the container's timezone.		
	 -->
	<context-param>
		<param-name>BIRT_VIEWER_TIMEZONE</param-name>
		<param-value></param-value>
	</context-param>
	
	<!--
		Report resources directory for preview. Defaults to ${birt home}
	-->
	<context-param>
		<param-name>BIRT_VIEWER_WORKING_FOLDER</param-name>
		<param-value></param-value>
	</context-param>
	
	<!--
		Temporary document files directory. Defaults to ${birt home}/documents
	-->
	<context-param>
		<param-name>BIRT_VIEWER_DOCUMENT_FOLDER</param-name>
		<param-value></param-value>
	</context-param>

	<!--
		Flag whether the report resources can only be accessed under the
		working folder. Defaults to true
	-->
	<context-param>
		<param-name>WORKING_FOLDER_ACCESS_ONLY</param-name>
		<param-value>true</param-value>
	</context-param>

	<!--
		Temporary image/chart directory. Defaults to ${birt home}/report/images
	-->
	<context-param>
		<param-name>BIRT_VIEWER_IMAGE_DIR</param-name>
		<param-value></param-value>
	</context-param>

	<!-- Engine log directory. Defaults to ${birt home}/logs -->
	<context-param>
		<param-name>BIRT_VIEWER_LOG_DIR</param-name>
		<param-value></param-value>
	</context-param>

	<!-- Report engine log level -->
	<context-param>
		<param-name>BIRT_VIEWER_LOG_LEVEL</param-name>
		<param-value>WARNING</param-value>
	</context-param>

	<!--
		Directory where to store all the birt report script libraries (JARs).
		Defaults to ${birt home}/scriptlib
	-->
	<context-param>
		<param-name>BIRT_VIEWER_SCRIPTLIB_DIR</param-name>
		<param-value></param-value>
	</context-param>
	
	<!-- Resource location directory. Defaults to ${birt home} -->
	<context-param>
		<param-name>BIRT_RESOURCE_PATH</param-name>
		<param-value></param-value>
	</context-param>

	<!-- Preview report rows limit. An empty value means no limit. -->
	<context-param>
		<param-name>BIRT_VIEWER_MAX_ROWS</param-name>
		<param-value></param-value>
	</context-param>

	<!--
		Max cube fetch levels limit for report preview (Only used when
		previewing a report design file using the preview pattern)
	-->
	<context-param>
		<param-name>BIRT_VIEWER_MAX_CUBE_ROWLEVELS</param-name>
		<param-value></param-value>
	</context-param>
	<context-param>
		<param-name>BIRT_VIEWER_MAX_CUBE_COLUMNLEVELS</param-name>
		<param-value></param-value>
	</context-param>

	<!-- Memory size in MB for creating a cube. -->
	<context-param>
		<param-name>BIRT_VIEWER_CUBE_MEMORY_SIZE</param-name>
		<param-value></param-value>
	</context-param>

	<!-- Defines the BIRT viewer configuration file -->
	<context-param>
		<param-name>BIRT_VIEWER_CONFIG_FILE</param-name>
		<param-value>WEB-INF/viewer.properties</param-value>
	</context-param>

	<!--
		Flag whether to allow server-side printing. Possible values are "ON"
		and "OFF". Defaults to "ON".
	-->
	<context-param>
		<param-name>BIRT_VIEWER_PRINT_SERVERSIDE</param-name>
		<param-value>ON</param-value>
	</context-param>

	<!--
		Flag whether to force browser-optimized HTML output. Defaults to true
	-->
	<context-param>
		<param-name>HTML_ENABLE_AGENTSTYLE_ENGINE</param-name>
		<param-value>true</param-value>
	</context-param>

	<!--
		Filename generator class/factory to use for the exported reports.
	-->
	<context-param>
		<param-name>BIRT_FILENAME_GENERATOR_CLASS</param-name>
		<param-value>org.eclipse.birt.report.utility.filename.DefaultFilenameGenerator</param-value>
	</context-param>

	<!--
		Viewer Filter used to set the request character encoding to UTF-8.
	-->
	<filter>
    	<filter-name>ViewerFilter</filter-name>
        <filter-class>org.eclipse.birt.report.filter.ViewerFilter</filter-class>
	</filter>
    <filter-mapping>
        <filter-name>ViewerFilter</filter-name>
        <servlet-name>ViewerServlet</servlet-name>
    </filter-mapping>
    <filter-mapping>
        <filter-name>ViewerFilter</filter-name>
        <servlet-name>EngineServlet</servlet-name>
    </filter-mapping>
    				
	<!-- Viewer Servlet Context Listener -->
	<listener>
		<listener-class>org.eclipse.birt.report.listener.ViewerServletContextListener</listener-class>
	</listener>

	<!-- Viewer HttpSession Listener -->
	<listener>
		<listener-class>org.eclipse.birt.report.listener.ViewerHttpSessionListener</listener-class>
	</listener>
	
	<!-- Viewer Servlet, Supports SOAP -->
	<servlet>
		<servlet-name>ViewerServlet</servlet-name>
		<servlet-class>org.eclipse.birt.report.servlet.ViewerServlet</servlet-class>
	</servlet>

	<!-- Engine Servlet -->
	<servlet>
		<servlet-name>EngineServlet</servlet-name>
		<servlet-class>org.eclipse.birt.report.servlet.BirtEngineServlet</servlet-class>
	</servlet>

	<servlet-mapping>
		<servlet-name>ViewerServlet</servlet-name>
		<url-pattern>/frameset</url-pattern>
	</servlet-mapping>
	
	<servlet-mapping>
		<servlet-name>ViewerServlet</servlet-name>
		<url-pattern>/run</url-pattern>
	</servlet-mapping>
	
	<servlet-mapping>
		<servlet-name>EngineServlet</servlet-name>
		<url-pattern>/preview</url-pattern>
	</servlet-mapping>

	<servlet-mapping>
		<servlet-name>EngineServlet</servlet-name>
		<url-pattern>/download</url-pattern>
	</servlet-mapping>

	<servlet-mapping>
		<servlet-name>EngineServlet</servlet-name>
		<url-pattern>/parameter</url-pattern>
	</servlet-mapping>	

	<servlet-mapping>
		<servlet-name>EngineServlet</servlet-name>
		<url-pattern>/document</url-pattern>
	</servlet-mapping>	

	<servlet-mapping>
		<servlet-name>EngineServlet</servlet-name>
		<url-pattern>/output</url-pattern>
	</servlet-mapping>	
	
	<servlet-mapping>
		<servlet-name>EngineServlet</servlet-name>
		<url-pattern>/extract</url-pattern>
	</servlet-mapping>

	<jsp-config>
		<taglib>
			<taglib-uri>/birt.tld</taglib-uri>
			<taglib-location>/WEB-INF/tlds/birt.tld</taglib-location>
		</taglib>
	</jsp-config>		

	<display-name>ZKProjectDemo</display-name>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:/config/application-context.xml,classpath:/config/datasource-context.xml</param-value>
	</context-param>
	<listener>
		<description>
		Used to cleanup when a session is destroyed</description>
		<display-name>ZK Session cleaner</display-name>
		<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
	</listener>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<listener>
		<listener-class>
			org.springframework.web.context.request.RequestContextListener</listener-class>
	</listener>
	<servlet>
		<description>
		The ZK loader for ZUML pages</description>
		<servlet-name>zkLoader</servlet-name>
		<servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
		<init-param>
			<param-name>update-uri</param-name>
			<param-value>/zkau</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet>
		<description>
		The asynchronous update engine for ZK</description>
		<servlet-name>auEngine</servlet-name>
		<servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>zkLoader</servlet-name>
		<url-pattern>*.zul</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
		<servlet-name>zkLoader</servlet-name>
		<url-pattern>*.zhtml</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
		<servlet-name>auEngine</servlet-name>
		<url-pattern>/zkau/*</url-pattern>
	</servlet-mapping>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
		<welcome-file>index.zul</welcome-file>
	</welcome-file-list>
</web-app>

Anybody can help me to solve this problem?

Thanks.

link publish delete flag offensive edit

answered 2009-10-07 08:09:20 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

you can try this

try {
	Messagebox.show("Question is pressed. Are you sure?", "Question",
		Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION, new EventListener() {
			@Override
			public void onEvent(Event event) throws Exception {
				if (((Integer) event.getData()).intValue() != Messagebox.OK) {
					System.out.println("Messagebox.CANCEL selected!");
					return;
				} else {
					System.out.println("Messagebox.OK selected!");
					return;
				}		
		});
} catch (InterruptedException e) {
	e.printStackTrace();
}

//jimmy

link publish delete flag offensive edit

answered 2009-10-07 11:01:23 +0800

baskaraninfo gravatar image baskaraninfo
536 2 2 9

Thank you, Jimmy. Thanks for your help :)

Your code is working as expected. I had referred this code block already.

In this option, I had faced a problem. That is, it doesn't wait until the user select an option. Because, its event based.

For ex:

Let us assume, am having two methods and each are independent of each other. I have a Messagebox.show method call in each of these methods. I want to execute the methods sequentially as first and second method as in an order.

While Messagebox.show is called in the first method, the control continue executing the second method and showing the Messagebox.show in the second method.

To prevent this, I want to copy second method's code block and need to paste inside first methods Messagebox.show's onEvent method. Hence need to place all the codes in a single method and results in a large number of lines within a single method.

Hence, am looking the other option. ie., Without overriding onEvent method.

Thanks.

link publish delete flag offensive edit

answered 2009-10-08 00:57:43 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

I will call the second method in the first method, like this

	public void onClick$btn() {
		try {
			if (Messagebox.CANCEL == Messagebox.show( "Question1 is pressed. Are you sure?", "Question",
					Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION)) {
				System.out.println("Messagebox.CANCEL selected!");
			} else {
				System.out.println("Messagebox.OK selected!");
			}
			secondMsgBox();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	private void secondMsgBox(){
		try {
			if (Messagebox.CANCEL == Messagebox.show( "Question2 is pressed. Are you sure?", "Question",
					Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION)) {
				System.out.println("secondMsgBox : Messagebox.CANCEL selected!");
			} else {
				System.out.println("secondMsgBox : Messagebox.OK selected!");
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

about MsgBox I only know those two of solvent

//jimmy

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-10-05 13:17:15 +0800

Seen: 7,976 times

Last updated: Nov 21 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More