ZK - Open Source Ajax Java FrameworkZK - Open Source Ajax Java Framework

YES / NO Confirmation issue

jeets
5 Mar 2010 00:13:43 GMT
5 Mar 2010 00:13:43 GMT

Hi All

I have 'Delete' button on a page.

Clicking which I want to display a pop-up message with Yes / NO options.
If the user clicks yes; delete button's event handler should be called on server (Which happens with no issues)
if her clicks no; nothing should happen and popup should be closed.

At the moment; I am using Messagebox.show.

The problem is: the delete button's event handler is getting exexcuted; irrespective what user clicks.
Resulting the record to be deleted even if you clicked 'No' to the delete confirmation.

Also tried using action="onclick:return confirm('Are you Sure')";
but it has the same issue of not being able to stop the delete.

Here is the code:

<button context="@{commRequest.id}" sclass="commButtonImage" id="btnDelete" image="./images/Image_Delete_Button.PNG" tooltiptext="Delete Communication Request">
<attribute name="onClick">{

if (Messagebox.show("Are you sure you wish to delete this record?", "Delete Confirm?", Messagebox.YES | Messagebox.NO, Messagebox.QUESTION) == Messagebox.NO) {

// DO SOMETHING TO PREVENT THE onClick$btnDelete FROM GETTING FIRED

}

}

</attribute>

</button>





Here is the delete buttons event handler in composer class

public void onClick$btnDelete(ForwardEvent event) throws CommTrackerException

{

// DELETION CODE

}

Can you please advise what I may be doing wrong here?

any help would be greatly appreciated....

Thanks a lot

mjablonskiTop Contributor
5 Mar 2010 00:41:47 GMT
5 Mar 2010 00:41:47 GMT

Hi,

seems to be that the event thread is disabled (which is default for ZK5). Please read the documenation about your options:

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

HTH, Maik

jeets
8 Mar 2010 19:55:53 GMT
8 Mar 2010 19:55:53 GMT

Hi mjablonski,

Thanks for your reply but still facing the same issue.

Clicking on the 'Delete' button; shows the Message box 'Modally'; which is correct and as required.

However, as soon as button 'No' is clicked; the execution goes ahead; the record gets deleted.

What I need to know here is
1. What code should I write in doNo() function (pls see the code below) to prevent the execution from continuing?
[The doYes() and doNo() fucntions are implemented under the <zscript> tags on the same .zul page; pls correct me if that is wrong]

2. As an alternatative; can I possibly check anything in the onClick$btnDelete event handler on the server end; to determine if the 'No' button was clicked ?

Thanks a Million

<button context="@{commRequest.id}" sclass="commButtonImage" id="btnDelete" image="./images/Image_Delete_Button.PNG" tooltiptext="Delete Communication Request">
<attribute name="onClick">{
Messagebox.show("Delete?", "Prompt", Messagebox.YES|Messagebox.NO,
Messagebox.QUESTION,
new EventListener() {
public void onEvent(Event evt) {
switch (((Integer)evt.getData()).intValue()) {
case Messagebox.YES: doYes(); break; //the Yes button is pressed
case Messagebox.NO: doNo(); break; //the No button is pressed
}
}
}
);
}
</attribute>
</button>

mjablonskiTop Contributor
8 Mar 2010 22:43:08 GMT
8 Mar 2010 22:43:08 GMT

The following code works for me:

<zk>
 <button label="Delete">
 <attribute name="onClick">
    Messagebox.show("Delete?", "Prompt", Messagebox.YES|Messagebox.NO, Messagebox.QUESTION,
     new EventListener() {
       public void onEvent(Event evt) {
         switch (((Integer)evt.getData()).intValue()) {
           case Messagebox.YES: doYes(); break; 
           case Messagebox.NO: doNo(); break; 
      }
    }
   });
 </attribute>
 </button>
 <zscript>
   public void doYes() {
     alert("yes");
   }

   public void doNo() {
     alert("no");
   }
   </zscript>
</zk>

jeets
11 Mar 2010 17:55:12 GMT
11 Mar 2010 17:55:12 GMT

Hey mjablonski,

I got it working as below.
However, not a very eligent solution so far since had to use Session from the view. :)

The onClick$btnDelete executes in both (all) cases; and it checks for the value in the session; and based on that it decides whether to delete a record or not.

Any suggestion with a better way to do this is very welcome.

<button id="btnDelete" context="@{commRequest.id}" sclass="commButtonImage" image="./images/Image_Delete_Button.PNG" tooltiptext="Delete Communication Request">
<attribute name="onClick">
Messagebox.show("Are you sure you wish to delete the request?", "Delete confirmation", Messagebox.YES|Messagebox.NO, Messagebox.QUESTION,
new EventListener() {
public void onEvent(Event evt) {
switch (((Integer)evt.getData()).intValue()) {
case Messagebox.YES: doYes(); break;
}
}
});
</attribute>
</button>
<zscript>
public void doYes() {
Session session = Sessions.getCurrent();
session.setAttribute("_Delete", "TRUE");

}
</zscript>

pdavie
18 Dec 2011 08:55:22 GMT
18 Dec 2011 08:55:22 GMT

You might want to look at this post too.