错误404,Ajax事件项目选择Primefaces 5.2

时间:2019-10-10 23:37:54

标签: jsf primefaces

当我单击条形图的项目时,我遇到了EROR 404的问题,此后我收到此错误,我不知道这是什么问题。

我使用了primefaces 5.2,java 8

根据文档添加下一个:

Java:

public ContractsBean() {
        modelChart = new BarChartModel();
         ChartSeries boys = new ChartSeries();
         boys.setLabel("Boys");
         boys.set("2004", 120);
         boys.set("2005", 100);
         boys.set("2006", 44);

         ChartSeries girls = new ChartSeries();
         girls.setLabel("Girls");
         girls.set("2004", 52);
         girls.set("2005", 60);
         girls.set("2006", 110);

         modelChart.addSeries(boys);
         modelChart.addSeries(girls);
         modelChart.setTitle("Bar Chart");
         modelChart.setLegendPosition("ne");

         Axis xAxis = modelChart.getAxis(AxisType.X);
         xAxis.setLabel("Gender");

         Axis yAxis = modelChart.getAxis(AxisType.Y);
         yAxis.setLabel("Births");
         yAxis.setMin(0);
         yAxis.setMax(200);
        }

    public BarChartModel getModelChart() { return modelChart; }

    public void itemSelectido(ItemSelectEvent event) {
     FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO,
    "Item selected", "Item Index: " + event.getItemIndex() +
    ", Series Index:" + event.getSeriesIndex());

     FacesContext.getCurrentInstance().addMessage(null, msg);
        System.out.println("chart impresooo");
     }

JSP:

<div style="width: 100%; height: 60%; margin-left: auto; margin-right: auto; margin-top: auto; margin-bottom: auto;">
                                    <p:chart type="bar" model="#{contractsBean.modelChart}">
                                        <p:ajax event="itemSelect" listener="#{contractsBean.itemSelectido}" />
                                    </p:chart>
                                    <p:growl id="growl"/>
                                </div>

after I clicked the item bar display the error

1 个答案:

答案 0 :(得分:1)

您的帖子中可能缺少一些内容,但是:

1)您需要使用private BarChartModel modelChart;

注释Bean。

2)您需要将BarChartModel声明为类属性<h:form> <p:growl id="growl" showDetail="true" /> <div style="width: 100%; height: 60%; margin-left: auto; margin-right: auto; margin-top: auto; margin-bottom: auto;"> <p:chart type="bar" model="#{contractsBean.modelChart}"> <p:ajax event="itemSelect" listener="#{contractsBean.itemSelectido}" update="growl" /> </p:chart> <p:growl id="growl"/> </div> </h:form>

3)您应该在表格中包含图表和ajax,如下所示:

update="growl"

4)注意,我还在p:ajax标签上添加了{{1}}