示例#1
0
  /** Method process chart tags, it collects chart options and data. */
  @Override
  public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
    super.encodeBegin(context, component);

    AbstractChart chart = (AbstractChart) component;

    VisitChart visitCallback = new VisitChart(chart);
    // copy attributes to parent tag and process data
    chart.visitTree(
        VisitContext.createVisitContext(FacesContext.getCurrentInstance()), visitCallback);

    // store data to parent tag
    component.getAttributes().put("chartData", visitCallback.getData());

    if (!visitCallback.isDataEmpty()) {
      component.getAttributes().put("charttype", visitCallback.getChartType());
      component.getAttributes().put("xtype", axisDataTypeToString(visitCallback.getKeyType()));
      component.getAttributes().put("ytype", axisDataTypeToString(visitCallback.getValType()));
    }

    // set flag whether request to server should be sent
    boolean anyServerSideListener = chart.getPlotClickListener() != null ? true : false;
    if (!anyServerSideListener) {
      // check if there is particular series listener
      List<MethodExpression> listeners = visitCallback.getParticularSeriesListeners();
      for (MethodExpression methodExpression : listeners) {
        if (methodExpression != null) {
          anyServerSideListener = true;
          break;
        }
      }
    }
    component.getAttributes().put("serverSideListener", anyServerSideListener);

    // client-side handlers for particular series
    component.getAttributes().put("handlers", visitCallback.getSeriesSpecificHandlers());

    // server-side listeners for particular series
    component
        .getAttributes()
        .put("particularSeriesListeners", visitCallback.getParticularSeriesListeners());
  }