Showing posts with label event. Show all posts
Showing posts with label event. Show all posts

Monday, January 27, 2014

ZK Modal Window prevent to close when used closable=true attribute.

Lets talk about some scenario or you can say business requirements.
Let us suppose a scenario I am opening a modal window to show employee information and user can edit few columns now after editing anything if user going to close the modal window i have to show a Zk MessageBox that something changed to you want to continue If user will press ok button then modal Window will close other wise user click on Cancel button modal Window should not be close.How to achieve this ? Any idea? May be lots of people can do it lots of way.
Here i got one issue thats why its encourage me to write this blog
I am using below code when someone click on Cross Mark of Modal Window


Now if you will check the above code it have a big drawback how i got that drawback read this official post about zk
By setting the closable property (Window.setClosable(boolean)) to true, a close button is shown for the window, which enables a to close the window by clicking the button. Once the user clicks on the close button, an onClose event is sent to the window which is processed by the onClose method of the Window component. Then, onClose, by default, detaches the window itself.
So here i in above code i got same issue as i am using closable="true" it automatically detach the window and when user press OK button of MessageBox i got Null Pointer exception because my Window is already detach or destroyed. To prevent this zk itself give a solution read this
Notice that event.stopPropagation() (Event.stopPropagation()) must be called to prevent the default onClose handler (Window.onClose()) being called.
So i used Zk this tip and used below code.


Now this line of code

Help me to prevent to close the modal Window..

ZK MVVM Get Which Event fired in ZUL

Most of time in ZK MVVM framework we used @Command to capture the event. But sometime we need to capture which event is fired by user so on that case we can use below code


Monday, February 4, 2013

ZK KeyStroke event with Windows Component in ZUL

ZK provide KeyStroke event we can see how can we add these KeyStroke event with windows in ZUL..
<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
 <window title="new page title" border="normal" id="inp"
    ctrlKeys="^a^s^d#f8"  attribute name="onOK"><![CDATA[
                        Messagebox.show("ENTER key is pressed", "OK",
                                Messagebox.OK, Messagebox.EXCLAMATION);
                        self.focus();
                    ]]></attribute>
                    <attribute name="onCancel"><![CDATA[
                        Messagebox.show("ESC key is pressed", "CANCEL",
                                Messagebox.OK, Messagebox.EXCLAMATION);
                        self.focus();
                    ]]></attribute>
                    <attribute name="onCtrlKey"><![CDATA[
                        int keyCode = ((KeyEvent) event).getKeyCode();
                        System.out.println(keyCode);
                        String s = "";
                        switch(keyCode){
                            case 65: s = "Ctrl+A";break;
                            case 119: s = "F8";break;
                            case 83:s="Ctrl+S";break;
                            case 68:s="Ctrl+D";break;
                        }
                        Messagebox.show(s+" is pressed", "CtrlKey",
                                Messagebox.OK, Messagebox.EXCLAMATION);
                        inp.focus();
                    ]]></attribute>
   
  
  
 </window>
</zk>