[ 
https://issues.apache.org/jira/browse/WICKET-1003?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12574442#action_12574442
 ] 

pasfilip edited comment on WICKET-1003 at 3/7/08 2:36 AM:
-----------------------------------------------------------

I've had a similar problem with the modal window that it refuses to close in 
firefox and ie6.
I only got this problem if using a modal window with a panel for content, using 
a page all seems to work fine.
I also got this problem in a form. In a testcase i made without forms the 
problem didn't present itself.
Also I wasn't using an ajaxindicating button but a plain AjaxButton (that 
submits the form).
The problem seems related to the way the timeout is being called that will 
close the modal window.
It seems for some reason window.parent doesn't return a window object but 
instead returns some html div element.
Isn't window.parent ALWAYS supposed to return a window object?
Is it possible that some of the js for wicket modal window modifies this parent?

I used the following code to get the modal window to close.
I think it will work without introducing any new bugs. Basically I test if 
window.parent has
a setTimeout method. If it does I use that to call the timeout  and if it 
doesn't I use window.setTimeout instead of
window.parent.setTimeout. See below for the sample code.

Another thing I thought could be improved about the modalwindow is that the 
code to close the modalwindow
be a template method which by default calls the static closecurrent method.
Also it could be useful to add a setShown method with protected visibility so 
people who override can set the shown flag appropriately.

Here's my implementation of the close method on the modal window:


    public class ModalWindow extends 
org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow{

  private final static Field shownField;
  
  static {
    try {
      shownField = 
org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow.class.getDeclaredField("shown");
      shownField.setAccessible(true);
    } catch ( SecurityException e ) {
      throw new RuntimeException("failed locating shown field on modalwindow 
due to security setting",e);
    } catch ( NoSuchFieldException e ) {
      throw new RuntimeException("failed locating shown field on 
modalwindow",e);
    }
  }
  
  public ModalWindow( String id ) {
    super( id );
  }

  public void close( AjaxRequestTarget target ) {
    String script =  "  var win;\n" 
      + "try {\n" + " win = window.parent.Wicket.Window;\n"
      + "} catch (ignore) {}\n"
      + "if (typeof(win) == \"undefined\" || typeof(win.current) == 
\"undefined\") {\n"
      + "  try {\n"
      + "     win = window.Wicket.Window;\n"
      + "  } catch (ignore) {}\n"
      + "}\n"
      +" var timeoutExecutor = window; \n if ( window.parent.setTimeout ) { 
timeoutExecutor = window.parent; } \n"
      + "if (typeof(win) != \"undefined\" && typeof(win.current) != 
\"undefined\") {\n"
      + "    timeoutExecutor.setTimeout(function() {\n" + "    
win.current.close();\n"
      + " }, 0);\n"
      + "} ";  
    target.appendJavascript(script);   
    setShown(false);
  }
  
  
  public void setShown(boolean shown) {
    try {
      shownField.setBoolean(this, shown);
    } catch ( IllegalArgumentException e ) {
      throw e;
    } catch ( IllegalAccessException e ) {
      throw new RuntimeException("could not invoke field shown",e);
    }
  }
}


Update:
Actually the code doesn't fix all issues. In some cases we're unable to close 
the modalwindow the first time it is shown. Using a custom button on the 
modalwindow did manage to close it.
Funny thing is the second time the window is show the close button (at the top 
left does work.)

Second Update:

After running some tests with a modified javascript I got the modalwindow to 
work in all situations in which we were using it. The solution seems to be to 
change the order of initialization of the win variable.
Here's what were using now:

  public void close( AjaxRequestTarget target ) {
    String script =  "  var win;\n" 
      + "if (typeof(window.parent) ) { \n"
      + "} \n"
       
      + "  try {\n"
      + "     win = window.Wicket.Window;\n"
      + "  } catch (ignore) { }\n"
      
      + "if (typeof(win) == \"undefined\" || typeof(win.current) == 
\"undefined\") {\n"
      + "try {\n" + " win = window.parent.Wicket.Window; \n"
      + "} catch (ignore) {  }\n"
      + "}\n"      
      +" var timeoutExecutor = window; \n if ( window.parent.setTimeout ) { 
timeoutExecutor = window.parent; } \n"
      + "if (typeof(win) != \"undefined\" && typeof(win.current) != 
\"undefined\") {\n"
      + "    timeoutExecutor.setTimeout(function() {\n" + "    
win.current.close();\n"
      + " }, 0);\n"
      + "} ";  
    target.appendJavascript(script);
    setShown(false);
  }





      was (Author: pasfilip):
    I've had a similar problem with the modal window that it refuses to close 
in firefox and ie6.
I only got this problem if using a modal window with a panel for content, using 
a page all seems to work fine.
I also got this problem in a form. In a testcase i made without forms the 
problem didn't present itself.
Also I wasn't using an ajaxindicating button but a plain AjaxButton (that 
submits the form).
The problem seems related to the way the timeout is being called that will 
close the modal window.
It seems for some reason window.parent doesn't return a window object but 
instead returns some html div element.
Isn't window.parent ALWAYS supposed to return a window object?
Is it possible that some of the js for wicket modal window modifies this parent?

I used the following code to get the modal window to close.
I think it will work without introducing any new bugs. Basically I test if 
window.parent has
a setTimeout method. If it does I use that to call the timeout  and if it 
doesn't I use window.setTimeout instead of
window.parent.setTimeout. See below for the sample code.

Another thing I thought could be improved about the modalwindow is that the 
code to close the modalwindow
be a template method which by default calls the static closecurrent method.
Also it could be useful to add a setShown method with protected visibility so 
people who override can set the shown flag appropriately.

Here's my implementation of the close method on the modal window:


    public class ModalWindow extends 
org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow{

  private final static Field shownField;
  
  static {
    try {
      shownField = 
org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow.class.getDeclaredField("shown");
      shownField.setAccessible(true);
    } catch ( SecurityException e ) {
      throw new RuntimeException("failed locating shown field on modalwindow 
due to security setting",e);
    } catch ( NoSuchFieldException e ) {
      throw new RuntimeException("failed locating shown field on 
modalwindow",e);
    }
  }
  
  public ModalWindow( String id ) {
    super( id );
  }

  public void close( AjaxRequestTarget target ) {
    String script =  "  var win;\n" 
      + "try {\n" + " win = window.parent.Wicket.Window;\n"
      + "} catch (ignore) {}\n"
      + "if (typeof(win) == \"undefined\" || typeof(win.current) == 
\"undefined\") {\n"
      + "  try {\n"
      + "     win = window.Wicket.Window;\n"
      + "  } catch (ignore) {}\n"
      + "}\n"
      +" var timeoutExecutor = window; \n if ( window.parent.setTimeout ) { 
timeoutExecutor = window.parent; } \n"
      + "if (typeof(win) != \"undefined\" && typeof(win.current) != 
\"undefined\") {\n"
      + "    timeoutExecutor.setTimeout(function() {\n" + "    
win.current.close();\n"
      + " }, 0);\n"
      + "} ";  
    target.appendJavascript(script);   
    setShown(false);
  }
  
  
  public void setShown(boolean shown) {
    try {
      shownField.setBoolean(this, shown);
    } catch ( IllegalArgumentException e ) {
      throw e;
    } catch ( IllegalAccessException e ) {
      throw new RuntimeException("could not invoke field shown",e);
    }
  }
}


Update:
Actually the code doesn't fix all issues. In some cases we're unable to close 
the modalwindow the first time it is shown. Using a custom button on the 
modalwindow did manage to close it.
Funny thing is the second time the window is show the close button (at the top 
left does work.)




  
> Modal Window Does Not Close When Using IndicatingAjaxButton
> -----------------------------------------------------------
>
>                 Key: WICKET-1003
>                 URL: https://issues.apache.org/jira/browse/WICKET-1003
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket-extensions
>    Affects Versions: 1.3.0-beta4
>         Environment: Ubuntu, Jetty, Eclipse
>            Reporter: Carlo M. Camerino
>            Assignee: Matej Knopp
>             Fix For: 1.3.2
>
>         Attachments: Modal.png, project.tar.gz, quickstart-closeDoesntWork.zip
>
>
> I have  a panel in my modal window. I have a button in my panel that closes 
> the modalwindow.
> If I use an indicatingajaxbutton for that button, the modalwindow does not 
> close properly.
> However if i use an ajaxlink, things go smoothly.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to