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 2011-01-06 21:03:57 +0800

tsinglongwu gravatar image tsinglongwu
30 2

updated 2011-01-06 21:45:13 +0800

Hi all,
my version is 5. the zk.xml is as follows:

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

than the Messagebox.show() in onClick() methord works ok without registering an EventListener,like this:

public void onClick$btn_delete{
    if (Messagebox.OK == Messagebox.show("Are you sure to delete?", "Question", Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION)))  {
           ... ...
    }
}

But now there's an error throwed:"doModal must be called in an event listener" when the Messagebox.show() not in the onClick() method.like this:
public List<?> getList(){
 try{ 
       ... ...
  }catch(Exception e){
    Messagebox.show("... ...");
  }
}

than i change to <disable-event-thread>true</disable-event-thread>. the error disappeared, but i must to register an EverListener in the Messagebox.show() which in the method onClick().

is't the only way to resolve this problem? what should i do?

thanx
Alex

link publish delete flag offensive edit

answered 2011-01-09 20:42:02 +0800

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

Hi Alex,
can you provide a sample for reproduce?
I tested my sample, it worked fine.

<zk>
	<zscript><![CDATA[
		public void show(){
			try{ 
			    throw new Exception();
			}catch(Exception e){
				if (Messagebox.OK == 
					Messagebox.show("Are you sure to delete?", "Question", 
							Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION))  {
				      System.out.println("in");
				}
			}
		}
	]]></zscript>
	<button label="click" onClick="show();"/>
</zk>

link publish delete flag offensive edit

answered 2011-01-10 19:24:20 +0800

tsinglongwu gravatar image tsinglongwu
30 2

Thanks for your reply, Jimmy

Your code also ran smoothly on my pc. My program is like this:

zk.xml

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

	<!-- Turn on the following if you want to use the trendy mold as default
		for all buttons.
	-->
	<library-property>
		<name>org.zkoss.zul.Button.mold</name>
		<value>trendy</value>
	</library-property>
	<library-property>
		<name>org.zkoss.zul.Button.autodisable</name>
		<value>true</value>
	</library-property>
	<!-- [ZK EE]
		Turn on if you want to enable the render-on-demand feature for grid.
		It improves the performance for huge grid.
		Default: false
	-->
	<library-property>
		<name>org.zkoss.zul.grid.rod</name>
		<value>true</value>
	</library-property>
	<!-- [ZK EE]
		Turn on if you want to enable the render-on-demand feature for listbox.
		It improves the performance for huge listbox.
		Default: false
	-->
	<library-property>
		<name>org.zkoss.zul.listbox.rod</name>
		<value>true</value>
	</library-property>
	
	<library-property>
		<name>org.zkoss.zul.progressbox.position</name>
		<value>center,top</value>
	</library-property>
	
	<system-config>
	<disable-event-thread>false</disable-event-thread>
	</system-config>
	
	<session-config>
		<session-timeout>1800</session-timeout>
	</session-config>
	
	<session-config>
		<device-type>ajax</device-type>
		<timeout-uri>/timeout.zul</timeout-uri>
	</session-config>

	<listener>
		<description> Mointor the statistic</description>
		<listener-class>org.zkoss.zk.ui.util.Statistic</listener-class>
	</listener>
</zk>

bw.zul:

<?xml version="1.0" encoding="UTF-8"?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="./bw_dialog"?>
<zk xmlns="http://www.zkoss.org/2005/zul"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">
	<window id="bw_dialog" apply="${bwCtrl}">
		<listbox id="listbox_bw" checkmark="true" multiple="true"
			model="@{bwCtrl.bw_list}" mold="paging" pageSize="10">
			<listhead>
				<listheader label="name"/>
			</listhead>
			<listitem self="@{each=one}">
				<listcell label="@{one}" />
			</listitem>
		</listbox>
	</window>
</zk>

BWCtrl.java:

@Controller("bwCtrl")
@Scope("prototype")
public class BlackWhiteDialogCtrl extends GenericForwardComposer {

	private Textbox tbox_name;

	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
                Messagebox.show("Hello world."); // the exception happens
	}

	public List<String> getBw_list() {
		List<String> list = null;
		try {
			throw new Exception();
		} catch (Exception e) {
			try {
				if (Messagebox.OK == 
					Messagebox.show("Are you sure to delete?", "Question", 
							Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION))  {
					Messagebox.show("OK.");
				}else{
					Messagebox.show("wrong.");
				}
			} catch (InterruptedException e1) {
				e1.printStackTrace();
			}
		}
		return list;
	}

}

The threw exception is as follows:

Servlet.service() for servlet  in context with path [] threw exception
org.zkoss.zk.ui.SuspendNotAllowedException: doModal must be called in an event listener
	at org.zkoss.zul.Window.doModal(Window.java:535)
	at org.zkoss.zul.Messagebox.show(Messagebox.java:244)
	at org.zkoss.zul.Messagebox.show(Messagebox.java:266)
	at com.pcmp.control.zk.BWCtrl.doAfterCompose(BWCtrl.java:24)

Thanks
Alex

link publish delete flag offensive edit

answered 2011-01-10 19:43:24 +0800

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

OK, You can move Messagebox.show("Hello world.") to onCreate method,

public class BlackWhiteDialogCtrl  extends GenericForwardComposer {
		
			public void onCreate(){
				Messagebox.show("Hello world."); // the exception happens
			}
		}

link publish delete flag offensive edit

answered 2011-01-10 21:13:17 +0800

tsinglongwu gravatar image tsinglongwu
30 2

Hi jimmy;

Many thanks for your reply.
I called getBw_list() in the onCreate(), and moved Messagebox.show() into the onCreate().

	public void onCreate() {
		try {
			if (null == getBw_list()) {
				Messagebox.show("getBw_list() error!");
				return;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public List<String> getBw_list() throws Exception {
		List<String> list = null;
		try {
			throw new Exception();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

thanx a lot!
Alex

link publish delete flag offensive edit

answered 2011-04-27 07:44:45 +0800

amoukkadem gravatar image amoukkadem
3

if u still have problem with ZK 5 or 6 messagebox, yo should add this tag on zk.xml
to display messagebox correctly and get the right returned value of method show

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

link publish delete flag offensive edit

answered 2011-04-27 21:39:14 +0800

tsinglongwu gravatar image tsinglongwu
30 2

thx amoukkadem,
I added it and get rid of the plobem.

link publish delete flag offensive edit

answered 2011-10-27 16:58:26 +0800

carpolva gravatar image carpolva
155 4

Thanks Jimmyshiau, your code example works perfectly to me :)

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();
}

link publish delete flag offensive edit

answered 2011-10-28 09:17:55 +0800

carpolva gravatar image carpolva
155 4

Hi guys, maybe you can help me.

I have a grid with some records, above that grid I have a DELETE button. The grid's first column are CHECKBOXES, so the user firstly needs to check one or more rows and then press the delete button in order to delete the checked rows. When I press the delete button I show a confirmation messageBox just like this:

public void onClick$deleteButton() {
     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 {
					//Executes the delete logic
					return;
				}		
		});
     } catch (InterruptedException e) {
	e.printStackTrace();
     }
}

The issue is that... when I press the delete button, before the messagebox appearance all the previous checked checkboxes turns unchecked and later the messagebox appears, so... in my onEvent logic I cannot determine which row is checked.

I'll appreciate any related help.

Best regards.

link publish delete flag offensive edit

answered 2011-10-28 09:43:12 +0800

carpolva gravatar image carpolva
155 4

A helpful tip:

My grid definition is:

<grid model="@{win$composer.dataList, load-after='deleteButton.onClick'}">

I know that grid is "reloaded" after pressing the delete button and because of that my previous checked checkboxes turn unchecked (their initial state)... so what's the best way to check a row, press the delete button, show the messagebox keeping the checkboxes actual state and later refresh the grid?

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