Forums Register Login

How can I close a JSF page from the Java Bean

+Pie Number of slices to send: Send
Hi,

I have a JSF window (dialog).
When the user presses the OK button I want to submit an action in the java bean.
After that I want to close the window.

What I do today is:



I guess there are 2 options:
1. To close the window (window.close()) from the jsf page itself after the submit, but I don't know how.
2. To do it from the add method in the java bean, but I also don't know how to do it...

Can anyone help me?
Thanks,
Efrat
+Pie Number of slices to send: Send
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
Screaming fools! It's nothing more than a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 13726 times.
Similar Threads
How to persist data of child window form
Close main window from popup window
Closing child window after executing Action
How to update Session variable with Form Data ?
URGENT Help Needed ...!!
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:00:22.