-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi, I have a problem with the status Label don't display inside a pop-up window. The below test program simulates situation where user selects a record in the main table, click Edit button to edit the record in a pop-up window, the status Label on the sub-window should first display the word "Processing..." and then once the processing finishes, it should say "Done!!". Problem is that the 1st string: "Processing..." never got displayed. Only the "Done!!" is displayed at the end. This happens for all IE, Firefox, and Chrome. Any insight is 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()'/> <!-- Edit button to edit the selected row --> <space spacing='1px'/> <button id='editBtn' label='Edit Record' autodisable='self' onClick='testWin.editBtn_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> <!-- ========= Pop-up window to edit selected record ============ --> <window id='subEditWin' visible='false' width='500px' border='normal' title='Edit Window' > <label value='Movie name:'/> <textbox id='movieNameTxtBox' width='80%' constraint='no empty'/> <separator/> <h:center> <label id='statusLbl'/> <button id='saveEditBtn' label='Save Record' onClick='testWin.saveEditBtn_onClick()'/> <button id='closeSubWinBtn' label='Close Window' onClick='testWin.closeSubWinBtn_onClick()'/> </h:center> </window> <!-- ========= End of pop-up Window ============ --> </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 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=============================== */ //=========================================================================== 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 private Window getSubWin() throws Exception { return (Window) getFellow("subEditWin"); }//end method private Textbox getSubWinTxtBox(Window subWin) throws Exception { return (Textbox) subWin.getFellow("movieNameTxtBox"); }//end method private Button getSubWinSaveBtn(Window subWin) throws Exception { return (Button) subWin.getFellow("saveEditBtn"); }//end method private Label getSubWinStatusLbl(Window subWin) throws Exception { return (Label) subWin.getFellow("statusLbl"); }//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 editBtn_onClick() throws Exception { if (this.getDetailLstBox().getSelectedItem() != null) { this.getSubWinStatusLbl(this.getSubWin()).setValue(""); this.getSubWinTxtBox(this.getSubWin()).setValue( (String) this.getDetailLstBox().getSelectedItem().getValue() ); this.getSubWin().doModal(); } }//end method public void unselectBtn_onClick() throws Exception { this.getDetailLstBox().clearSelection(); }//end method public void saveEditBtn_onClick() throws Exception { this.getSubWinStatusLbl(this.getSubWin()).setValue("Processing..."); //Simulate some processing time after user edit the record and save Thread.sleep(5000); this.getSubWinStatusLbl(this.getSubWin()).setValue("Done!!"); }//end method public void closeSubWinBtn_onClick() throws Exception { this.getSubWin().setVisible(false); }//end method }//end class
Have you tried commenting out the Thread.sleep() and ...setValue("Done!!") in saveEditBtn_onClick() to see if "Processing..." shows up?
Hi Clark, the "Processing..." shows up fine when it's the only command inside the method block. Here's something very strange that I notice: I comment out setValue("Done!!") while leaving setValue("Proccessing...") and Thread.sleep(5000) on, when I invoke the method by clicking Save Record button, the Thread.sleep got executed first and then the setValue("Processing") executed second!!!
@zknewbie1,
Please take a look at this smalltalk - Prompt the User before Doing a Long Operation with Echo Event
Hi Jumperchen, thanks for the article, I tried the new way that you suggested: display a busy box with org.zkoss.zk.ui.util.Clients.showBusy("Please wait..."); call the "onLater" event with Events.echoEvent("onLater", <component>, null); and finally close the busy box with ...Clients. clearBusy(). Everything works fine now and thanks very much for that. However, I'm kinda curious to know why my old way seems to have the order of execution in reverse? why the Label displays the status string after the processing?? Any insight would be greatly appreciated...
because your code is run in the same request, which means it will update the response until all of the Java code being run finish.
Thanks very much Jumperchen. I still have a lot to learn about this cool framework. By the way, I have another thread called: "Messagebox pops up without being called" which really bugging me for the last couple days. Please take a look and give some insight if you have some times. Again, thanks so much...
Asked: 2010-08-30 10:44:39 +0800
Seen: 440 times
Last updated: Aug 31 '10