通过单击一系列条形图重定向到JSF 2.0中的新页面

时间:2013-06-06 09:33:46

标签: jsf-2

我是JSF的新手。我正在构建一个xhtml页面,其中我正在显示一个条形图。 当我点击其中一个条形图栏时,我想使用导航规则将其重定向到新的xhtml页面。

代码示例:

条形码代码:

<p:layoutUnit position="south" size="350" resizable="true"
                closable="true" collapsible="true">
                <p:growl id="barChartGrowl" showDetail="true" />
                <p:barChart orientation="vertical" id="tkChart"
                    value="#{chartCreateService.categoryChartModel}"
                    legendPosition="ne" title="Human Capital Model Analysis" minY="0"
                    maxY="100" yaxisLabel="Score" style="height:300px;width:700px"
                    barMargin="50" animate="true">
                    <p:ajax event="itemSelect" listener="#{userInput.barChartClicked}"
                        update="barChartGrowl" />
                </p:barChart>
            </p:layoutUnit>

Bean:

public String barChartClicked(ItemSelectEvent event) {
        try {
            System.out.println("In Bar Chart Clicked...");
            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO,
                    "Item selected", "Item Index: " + event.getItemIndex() + ", Series Index:" + event.getSeriesIndex());
            FacesContext.getCurrentInstance().addMessage(null, msg);
            int itemIndex = event.getItemIndex();
            int seriesIndex = event.getSeriesIndex();
            System.out.println("Item Index :"+ itemIndex);
            System.out.println("Series Index :"+ seriesIndex);
            objSummeryAttributeCharts.displaySelectedGroupResults(seriesIndex,itemIndex,objResults,objChart.getCategoryChartModel());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "showAttributeResults";
    }

Faces-config条目:

navigation-rule>
        <from-view-id>/pages/peerGroupAnalysis.jsf</from-view-id>
        <navigation-case>
            <from-outcome>showAttributeResults</from-outcome>
            <to-view-id>/pages/categoryResults.jsf</to-view-id>
        </navigation-case>
    </navigation-rule>

每件事都运行正常,我正在获取用户在bean中正确点击的栏的项索引和系列索引。但它没有重定向到另一页。 有没有其他方法可以重定向到JSF中的新页面或者我做错了什么?

请求帮助......

谢谢..

1 个答案:

答案 0 :(得分:0)

您通常不会导航ajax请求,通常会更新dom。 如果您需要导航,则可能需要使用重定向,例如

  

FacesContext ctx = FacesContext.getCurrentInstance();
ExternalContext extContext = ctx.getExternalContext();
String url = extContext.encodeActionURL(ctx.getApplication().getViewHandler().getActionURL(ctx, "/pages/categoryResults.jsf")); 

try {
    extContext.redirect(url);
} catch (IOException e) {
    e.printStackTrace();
}