-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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.
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))) { ... ... } }
public List<?> getList(){ try{ ... ... }catch(Exception e){ Messagebox.show("... ..."); } }
is't the only way to resolve this problem? what should i do?
thanx
Alex
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>
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
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 } }
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
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>
thx amoukkadem,
I added it and get rid of the plobem.
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(); }
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.
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?
Asked: 2009-10-05 13:17:15 +0800
Seen: 7,976 times
Last updated: Nov 21 '11