I have a main window (window1), a second window (window2) which was opened by window.open() from a managed bean and a managed bean (controller).
window2 triggers a method in the controller. If a specific condition is true, controller should close window2 and change the page from /test/page1.xhtml to /test/page2.xhtml in window1.
The method in the controller looks like that:
String result = model.doSomething();
if (result.matches("[0-9]+")) {
RequestContext.getCurrentInstance().execute("window.close()");
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
try {
FacesContext.getCurrentInstance().getExternalContext().redirect(request.getContextPath() + "/test/page1.xhtml");
} catch (IOException e) {
MessageHelper.showMessage(null, e.getMessage(), FacesMessage.SEVERITY_ERROR, this);
}
}
The problem is the line HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
I guess.
I have no idea how to command window1 to change the page from controller immediately after closing window2.
The solution has to work under IE 11. I'm using Primefaces 5.2 and JSF 2.0.