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..

No comments:

Post a Comment