Java 从托管bean事件JSF重定向

Java 从托管bean事件JSF重定向,java,redirect,jsf-2,Java,Redirect,Jsf 2,我有一个包含饼图的JSF页面。这个想法是,当扇形图的扇区被单击时,应用程序将重定向到另一个页面。我面临着重定向的挑战,因为它只是将完整的url带到页面,这不是动态的,因为它将根据环境而变化。我的ItemSelect方法是: public void itemSelect(ItemSelectEvent event) { try { FacesContext.getCurrentInstance(). getExternalCont

我有一个包含饼图的JSF页面。这个想法是,当扇形图的扇区被单击时,应用程序将重定向到另一个页面。我面临着重定向的挑战,因为它只是将完整的url带到页面,这不是动态的,因为它将根据环境而变化。我的ItemSelect方法是:

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("/OpenedAccountsProductTypeLevel.xhtml");
我的问题是如何在不必放入整个URL的情况下重定向???

尝试使用

 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();
    }
试用

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