【问题标题】:Redirect from managed bean event JSF从托管 bean 事件 JSF 重定向
【发布时间】:2014-04-01 11:31:21
【问题描述】:

我有一个包含饼图的 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("/faces/OpenedAccountsProductTypeLevel.xhtml");

我也试过了:

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

我的问题是如何在无需放入整个 URL 的情况下进行重定向??

【问题讨论】:

    标签: java redirect jsf-2


    【解决方案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();
        }
    

    【讨论】:

      猜你喜欢
      • 2013-03-05
      • 2017-06-14
      • 2023-03-05
      • 2011-08-07
      • 2016-07-05
      • 2012-07-27
      • 2016-07-09
      • 2012-11-08
      相关资源
      最近更新 更多