0

Messagebox pops up without being called

asked 2010-08-27 16:35:10 +0800

zknewbie1 gravatar image zknewbie1
370 4

Hi, this problem only happens on IE7, not Firefox nor Chrome. Basically, my attached program below simulates situation where the user still have some records selected in the main table to be processed, when he picks a different category filter, a messagebox will pop up to prompt him to either proceed and lost the selected records OR go back to finish some work on the selected records. For simplicity purpose, the Unselected Record button simulates some action to be done on the selected records. The problem happens when I: select some records in the main table, change the Category, click No to the Messagebox prompt, and then click Unselected Record button. Although this button never calls the Messagebox, it still pops up a second time!! Any insight would be greatly appreciated. Thanks....

ZUL file:
======

<?xml version="1.0" encoding="UTF-8"?>
<zk xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xmlns='http://www.zkoss.org/2005/zul'
    xmlns:h='http://www.w3.org/1999/xhtml'
    xsi:schemaLocation='http://www.zkoss.org/2005/zul WEB-INF/xsd/zul.xsd'
    anyAttribute= " ">


<window id='testWin' use='ControllerTestWin' 
        border='normal' title='A Test Page'>
  <label value='Select a category:'/><separator/>
  <!-- This is the movie category List box -->
  <listbox id='categoryLstBox' mold="select" rows="1"
     onSelect='testWin.categoryLstBox_onSelect()'>
     <listitem label='Cartoons' value='C' selected='true'/>
     <listitem label='ActionMovies' value='A' />
  </listbox>
  <!-- CLick this button to display the Category movie details -->
  <space spacing='1px'/>
  <button id='displayBtn' label='Display Detail' autodisable='self'
     onClick='testWin.displayBtn_onClick()'/>
  <!--  Deselect button that simulates some actions on the selected records -->
  <space spacing='1px'/>
  <button id='unselectBtn' label='UnSelect Records' autodisable='self'
     onClick='testWin.unselectBtn_onClick()'/>
  <!-- This listbox display the movies names per selected Category -->
  <separator/>
  <listbox id='detailLstBox' width='400px' checkmark='true' multiple='true'>
    <listhead sizable='true'>
      <listheader label='Name'/>
    </listhead>
  </listbox>

</window>
</zk>

Controller file:
==========

import java.sql.SQLException;
import javax.servlet.ServletContext;
import java.util.*;
import org.zkoss.zul.*;
import org.zkoss.zk.ui.*;
import org.zkoss.zk.ui.event.*;
import org.zkoss.zk.ui.event.EventListener;

/** Controller class for the verifyWindow page */

public class ControllerTestWin extends Window {
  private ZKCommonUtils zkCommonUtils = new ZKCommonUtils();
  private List<String> nameList = new ArrayList();
  private Map<String, String[]> nameHash = Collections.synchronizedMap(new HashMap());
  private int existingSelectIndex = 0;
  /**  Constructor */
  public ControllerTestWin() {
    this.nameHash.put("C", new String[] {"Tom And Jerry", "Tweety and Sylvester", "Looney Toons"});
    this.nameHash.put("A", new String[] {"Enter the Dragon", "Rumble in the Bronx", "Kickboxer"});
  }//end constructor
  /** ===================Getter and Setter=============================== */
  public void setNameList(List<String> nameList) {
    this.nameList = nameList;
  }//end method
  public List<String> getNameList() {
    return this.nameList;
  }//end method
  //===========================================================================
  private Listbox getCategoryLstBox() throws Exception {
    return (Listbox) getFellow("categoryLstBox");  
  }//end method
  private Button getDisplayBtn() throws Exception {
    return (Button) getFellow("displayBtn");  
  }//end method
  private Listbox getDetailLstBox() throws Exception {
    return (Listbox) getFellow("detailLstBox");  
  }//end method
  // ======================Event Handlers======================================        
  public void categoryLstBox_onSelect() throws Exception {
    if (this.getDetailLstBox().getSelectedItems().isEmpty()) {
      this.existingSelectIndex = this.getCategoryLstBox().getSelectedItem().getIndex();
    }//if no record selected
    else {
      Messagebox.show("There are still selected rows in the main table. \n " +
                      "Click YES if you want to proceed without saving or \n " +
                      "Click NO to go back and finish your work.",
                      "Confirmation Prompt",
                      Messagebox.YES | Messagebox.NO,
                      Messagebox.QUESTION,
                      new EventListener() {
                        public void onEvent(Event evt) throws Exception{
                          switch (((Integer) evt.getData()).intValue()) {
                          case Messagebox.YES:
                            existingSelectIndex = getCategoryLstBox().getSelectedItem().getIndex();
                            getDetailLstBox().getChildren().clear();
                            break;
                          case Messagebox.NO:
                            //restore the previous selected item
                            getCategoryLstBox().setSelectedIndex(existingSelectIndex);
                            break;
                          }//end switch
                        }//end onEvent()
                      }//end EventListener instance
                      );
      
    }//end if there're selected records
  }//end method

  public void displayBtn_onClick() throws Exception {
    String categoryKey = (String) this.getCategoryLstBox().getSelectedItem().getValue();  
    String[] categoryValue = this.nameHash.get(categoryKey);
    this.getDetailLstBox().getChildren().clear();
    for (int i=0; i < categoryValue.length; i++){
      Listitem listItem = new Listitem(categoryValue<i >, categoryValue<i >);
      listItem.setParent(this.getDetailLstBox());
    }//end for
  }//end method

  public void unselectBtn_onClick() throws Exception {
    this.getDetailLstBox().clearSelection();
  }//end method

}//end class

delete flag offensive retag edit

10 Replies

Sort by ยป oldest newest

answered 2010-08-30 21:28:07 +0800

zknewbie1 gravatar image zknewbie1
370 4

Hi, I just tried running on IE8 and the Messagebox does not pop up at all!! Could anyone try to run my code as is on IE7 and IE8 and see if you get the same symptoms? Thanks much.

link publish delete flag offensive edit

answered 2010-08-30 21:59:47 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

Hi zknewbie1,
Could you list step by step user actions becuase your description is not clear? I tried it on IE8 but couldn't reproduce.

link publish delete flag offensive edit

answered 2010-08-30 22:02:19 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

what ZK version are you using?

link publish delete flag offensive edit

answered 2010-08-31 08:03:13 +0800

zknewbie1 gravatar image zknewbie1
370 4

Hi Ashishd, I use ZK ver. 5.0.3. Here're the user actions:
1. select Cartoons category
2. click Display Detail
3. check a few records checkboxes
4. select ActionMovies
5. click No button on the pop-up window (the pop-up doesn't show on my IE8)
6. click UnSelect Records (the pop-up re-appears a second time on my IE7)
7. if pop-up re-displays, just click No button
8. click UnSelect Records a second time, and the selected records will be unchecked.

So as you see in steps 5 and 6, I get 2 issues: pop-up doesn't show on my IE8; and pop-up re-appears a second time without being invoked on my IE7. Please let me know if you get the same symptoms on your system. Thanks Ashishd.

link publish delete flag offensive edit

answered 2010-09-01 03:30:04 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

Hi zknewbie1,

I guess that is a bug, and here a workaround that you can invoke getCategoryLstBox().invalidate() to avoid this issue.
For example,

 getCategoryLstBox().setSelectedIndex(existingSelectIndex);
getCategoryLstBox().invalidate();

link publish delete flag offensive edit

answered 2010-09-01 04:23:26 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

By the way, I post a bug here

link publish delete flag offensive edit

answered 2010-09-01 08:53:49 +0800

zknewbie1 gravatar image zknewbie1
370 4

Thanks a lot Jumperchen. That fixes the problem on my IE7 now. Any insight on item 5, where the Messagebox doesn't pop up on IE8? Thanks..

link publish delete flag offensive edit

answered 2010-09-03 10:30:37 +0800

zknewbie1 gravatar image zknewbie1
370 4

Hi Jumperchen, did you get a chance to run the code on IE8 to see if you get the same symptom as mine: Messagebox doesn't pop up (Step 5 in the above user actions list)? Thanks.

link publish delete flag offensive edit

answered 2010-09-07 22:29:14 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

Hi zknewbie1,
I just verified for both the problems you mentioned for IE7 (popup appearing 2nd time) & IE8 (popup not appearing first time) the bug is fixed.

link publish delete flag offensive edit

answered 2010-09-08 08:05:42 +0800

zknewbie1 gravatar image zknewbie1
370 4

Hi Ashishd, thanks very much for letting me know that both versions of IEs now work after Jumperchen's fix. My IE8 probably has some configs that blocks pop-up window. I'll play around with the configs to see if can allow pop-ups. Thanks...

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: 2010-08-27 16:35:10 +0800

Seen: 450 times

Last updated: Sep 08 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More