2016-08-02 1 views
1

私はメインウィンドウ(window1)、マネージドBeanとマネージドBean(controller)からwindow.open()で開いた第2のウィンドウ(window2)を持っています。メインウィンドウを別のウィンドウからトリガされたマネージドBeanのメソッドから更新する(リダイレクトする)方法は?

ウィンドウ2は、コントローラ内のメソッドをトリガします。特定の条件が真である場合、コントローラはwindow2を閉じ、window1の/test/page1.xhtmlから/test/page2.xhtmlにページを変更する必要があります。

コントローラのメソッドは、次のようになります。

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); 
    } 
} 

問題は、私は推測するHttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();ラインです。 私はwindow2を閉じる直後にwindow1にコントローラからページを変更するようにどのように指示するのか分かりません。

ソリューションはIE 11で動作する必要があります。 私はPrimefaces 5.2とJSF 2.0を使用しています。

答えて

0

これはJavaScriptを使用して簡単に行うことができます。 window.close()の前にwindow.opener.document.location = '{yourlocation}';を追加してください。だから、:

RequestContext.getCurrentInstance().execute(
    "window.opener.document.location = '"+ request.getContextPath() +"/test/page1.xhtml';"+ 
    "window.close()" 
); 

も参照してください:

+0

はどうもありがとうございました。完璧に動作します。 –

関連する問題