Exemplo n.º 1
0
  @Override
  public void decode(FacesContext context, UIComponent component) {
    super.decode(context, component);

    if (!component.isRendered()) {
      return;
    }
    Map<String, String> requestParameterMap = context.getExternalContext().getRequestParameterMap();

    if (requestParameterMap.get(component.getClientId(context)) != null) {
      String xParam = requestParameterMap.get(getFieldId(component, X_VALUE));
      String yParam = requestParameterMap.get(getFieldId(component, Y_VALUE));
      String pointIndexParam = requestParameterMap.get(getFieldId(component, POINT_INDEX));
      String eventTypeParam = requestParameterMap.get(getFieldId(component, EVENT_TYPE));
      String seriesIndexParam = requestParameterMap.get(getFieldId(component, SERIES_INDEX));
      try {

        if (PLOT_CLICK_TYPE.equals(eventTypeParam)) {
          double y = Double.parseDouble(yParam);
          int seriesIndex = Integer.parseInt(seriesIndexParam);
          int pointIndex = Integer.parseInt(pointIndexParam);
          String x = xParam;
          new PlotClickEvent(component, seriesIndex, pointIndex, x, y).queue();
        }
      } catch (NumberFormatException ex) {
        throw new FacesException("Cannot convert request parmeters", ex);
      }
    }
  }
Exemplo n.º 2
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());
  }