myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Myfaces Wiki] Update of "JavascriptOpenNewWindow" by Rene Grob
Date Sun, 25 Feb 2007 16:36:53 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Myfaces Wiki" for change notification.

The following page has been changed by Rene Grob:
http://wiki.apache.org/myfaces/JavascriptOpenNewWindow

------------------------------------------------------------------------------
   * The browser window is opened although there are validation errors.
   * Validation errors are displayed in the newly opened window which is very confusing.
   * The appearance of the new window cannot be controlled (e.g. hiding of the location bar)
- If no model updated is needed then setting the attribute "immediate" to "true" can be used
to work around the validation problems.
+ If no model update is needed then setting the attribute "immediate" to "true" can be used
to work around the validation problems.
  
  == Using HTML and Javascript ==
  {{{
@@ -60, +60 @@

  }
  }}}
  
+ === Closing the popup window ===
+ If the close button has a "cancel" semantic, we can use a simple DHTML script:
+ {{{
+ <a href="#" onclick="window.close();">open popup</a>
+ }}}
+ The window will simply close. The server will not notice anything.
+ 
+ === Submit form and close the popup window ===
+ For a proper action handling which goes through the whole request lifecycle we use an action
listener:
+ {{{
+ <h:commandLink actionListener="#{popupBean.closeWindow}" value="submit and close" />
+ }}}
+ 
+ {{{
+ public void closeWindowClicked(ActionEvent event) {
+     FacesContext facesContext = FacesContext.getCurrentInstance();
+ 
+     String javaScriptText = "window.close();";
+     
+     // Add the Javascript to the rendered page's header for immediate execution
+     AddResource addResource = AddResourceFactory.getInstance(facesContext);
+     addResource.addInlineScriptAtPosition(facesContext, AddResource.HEADER_BEGIN, javaScriptText);
        
+ }
+ }}}
+ Note: If there is a validation error the window will not close unless the "immediate" attribute
of the commandLink is set to "true".
+ 

Mime
View raw message