2014-02-28 112 views
0

我有一個包含餅圖的JSF頁面。這個想法是,當單擊餅圖扇區時,應用程序會重定向到另一個頁面。我正面臨挑戰重定向,因爲它只是將全網址帶到非動態頁面,因爲它會根據環境而改變。我ItemSelect方法是:從託管bean事件重定向JSF

public void itemSelect(ItemSelectEvent event) { 

     try { 

      FacesContext.getCurrentInstance(). 
      getExternalContext().redirect("http://localhost:8084/SIMBANK_BI/faces/OpenedAccountsProductTypeLevel.xhtml"); 

     } catch (IOException asd) { 
      System.err.println(asd.getMessage()); 
     } 
    } 

我的JSF頁面:

<left> 
      <p:growl id="growl" showDetail="true" /> 
      <p:pieChart id="custom" value="#{OpenedAccountsBranchLevelBean.pieModel}" legendPosition="w" showDataLabels="true" 
       style="width:500px;height:400px" sliceMargin="2"> 
        <p:ajax event="itemSelect" listener="#{OpenedAccountsBranchLevelBean.itemSelect}" update="growl" /> 
      </p:pieChart> 
     </left> 

我都試過;

FacesContext.getCurrentInstance(). 
       getExternalContext().redirect("/faces/OpenedAccountsProductTypeLevel.xhtml"); 

我也曾嘗試:

FacesContext.getCurrentInstance(). 
       getExternalContext().redirect("/OpenedAccountsProductTypeLevel.xhtml"); 

我的問題是我怎麼能重定向,而無需在整個URL的地方?

回答

1

嘗試使用

FacesContext context = FacesContext.getCurrentInstance(); 
    HttpServletRequest origRequest = (HttpServletRequest)context.getExternalContext().getRequest(); 
    contextPath = origRequest.getContextPath(); 
try { 
     FacesContext.getCurrentInstance().getExternalContext() 
       .redirect(contextPath + "/faces/OpenedAccountsProductTypeLevel.xhtml"); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
+0

由於這個實際工作。 – ErrorNotFoundException