• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSF Server Side Validations with close window?

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have an issue in Java server faces validation part.
The thing is i am doing server side validation for a pop up page,
i have to close the pop up page once the validation is succeeded,
the issue is if i use window.close() at on click of save button,script will be executed at the client
side to close the pop up page and then only the action controller method gets triggered,so there
will be no page available to show the Faces Message which is added at the server side.

How to achieve this ?

Thanks In Advance,

Cheers,

Sundar
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found the below text at another site (http://www.java-samples.com/showtutorial.php?tutorialid=476):

Closing the popup window

If the close button has a "cancel" semantic, we can use a simple OutputLink:
<h:outputLink onclick="window.close(); return false;" value="#">
<h:outputText value="cancel" />
</h:outputLink>

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 need to use an action listener:
<h:commandLink actionListener="#{popupBean.closeWindowClicked}" 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".

hope that helps,
Tom
 
reply
    Bookmark Topic Watch Topic
  • New Topic