Esempio n. 1
0
  /**
   * Set the values of the form widget
   *
   * @param tenantID the tenantID
   * @param formWidget the widget
   * @param evaluatedExpressions
   * @param context the context including the URL parameters
   * @throws FormNotFoundException
   * @throws FormServiceProviderNotFoundException
   * @throws SessionTimeoutException
   * @throws IOException
   * @throws FileTooBigException
   * @throws FormInitializationException
   */
  public void setFormWidgetValues(
      final long tenantID,
      final FormWidget formWidget,
      final Map<String, Serializable> evaluatedExpressions,
      final Map<String, Object> context)
      throws FormNotFoundException, FormServiceProviderNotFoundException, SessionTimeoutException,
          IOException, FileTooBigException, FormInitializationException {
    final String widgetId = formWidget.getId();
    final FormServiceProvider formServiceProvider =
        FormServiceProviderFactory.getFormServiceProvider(tenantID);
    final Locale locale = (Locale) context.get(FormServiceProviderUtil.LOCALE);
    formWidget.setLabel(
        getStringValue(
            evaluatedExpressions.get(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_LABEL)));
    formWidget.setTitle(
        getStringValue(
            evaluatedExpressions.get(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_TITLE)));
    if (formWidget.getSubtitle() != null) {
      formWidget
          .getSubtitle()
          .setLabel(
              getStringValue(
                  evaluatedExpressions.get(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_SUBTITLE)));
    }
    formWidget.setPopupTooltip(
        getStringValue(
            evaluatedExpressions.get(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_TOOLTIP)));
    formWidget.setDisplayCondition(
        getDisplayCondition(
            formWidget.getDisplayConditionExpression(),
            evaluatedExpressions.get(
                widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_DISPLAY_CONDITION)));

    final Object value = getFormWidgetInitialValues(formWidget, evaluatedExpressions);
    if (formWidget.getType().name().startsWith("FILE")
        || formWidget.getType().equals(WidgetType.IMAGE) && formWidget.isDisplayAttachmentImage()) {
      final String filePaths = formWidget.getFilePaths();
      if (filePaths != null) {
        final FormFieldValue fileFieldValue = new FormFieldValue(filePaths, File.class.getName());
        formWidget.setInitialFieldValue(fileFieldValue);
      } else {
        formWidget.setInitialFieldValue(
            formServiceProvider.getAttachmentFormFieldValue(value, context));
      }
    } else if (!formWidget.getType().name().startsWith("BUTTON")) {
      // convert the value object returned into a FormFieldValue object.
      formWidget.setInitialFieldValue(getFieldValue(value, formWidget, locale));
      // set the available values list from a groovy expression for listboxes, radiobutton groups,
      // checkbox groups...
      setFormWidgetAvailableValues(formWidget, evaluatedExpressions);
    }
  }
Esempio n. 2
0
  /**
   * Generate the Map of groovy expressions to evaluate for a widget
   *
   * @param formWidget the widget
   * @param context the context including the URL parameters
   * @return the Map of expressions to evaluate
   */
  protected List<Expression> getWidgetExpressions(
      final FormWidget formWidget, final Map<String, Object> context) {
    final String widgetId = formWidget.getId();
    final List<Expression> expressionsToEvaluate = new ArrayList<Expression>();
    if (formWidget.getLabelExpression() != null) {
      final Expression labelExpression = formWidget.getLabelExpression();
      labelExpression.setName(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_LABEL);
      expressionsToEvaluate.add(labelExpression);
    }
    if (formWidget.getTitleExpression() != null) {
      final Expression titleExpression = formWidget.getTitleExpression();
      titleExpression.setName(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_TITLE);
      expressionsToEvaluate.add(titleExpression);
    }
    if (formWidget.getSubtitle() != null) {
      final Expression subtitleLabelExpression = formWidget.getSubtitle().getLabelExpression();
      if (subtitleLabelExpression != null) {
        subtitleLabelExpression.setName(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_SUBTITLE);
        expressionsToEvaluate.add(subtitleLabelExpression);
      }
    }
    if (formWidget.getPopupTooltipExpression() != null) {
      final Expression popupToolTipExpression = formWidget.getPopupTooltipExpression();
      popupToolTipExpression.setName(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_TOOLTIP);
      expressionsToEvaluate.add(popupToolTipExpression);
    }
    addFormWidgetValueExpressionToEvaluate(formWidget, expressionsToEvaluate, context);
    addFormWidgetAvailableValuesExpressions(formWidget, expressionsToEvaluate);

    if (WidgetType.TABLE.equals(formWidget.getType())
        || WidgetType.EDITABLE_GRID.equals(formWidget.getType())) {
      if (formWidget.getValueColumnIndexExpression() != null) {
        final Expression valueColumnIndexExpression = formWidget.getValueColumnIndexExpression();
        valueColumnIndexExpression.setName(
            widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_VALUE_COLUMN_INDEX);
        expressionsToEvaluate.add(valueColumnIndexExpression);
      }
      if (formWidget.getMaxColumnsExpression() != null) {
        final Expression valueColumnIndexExpression = formWidget.getMaxColumnsExpression();
        valueColumnIndexExpression.setName(
            widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_MAX_COLUMNS);
        expressionsToEvaluate.add(valueColumnIndexExpression);
      }
      if (formWidget.getMinColumnsExpression() != null) {
        final Expression minColumnsExpression = formWidget.getMinColumnsExpression();
        minColumnsExpression.setName(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_MIN_COLUMNS);
        expressionsToEvaluate.add(minColumnsExpression);
      }
      if (formWidget.getMaxRowsExpression() != null) {
        final Expression maxRowsExpression = formWidget.getMaxRowsExpression();
        maxRowsExpression.setName(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_MAX_ROWS);
        expressionsToEvaluate.add(maxRowsExpression);
      }
      if (formWidget.getMinRowsExpression() != null) {
        final Expression minRowsExpression = formWidget.getMinRowsExpression();
        minRowsExpression.setName(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_MIN_ROWS);
        expressionsToEvaluate.add(minRowsExpression);
      }
      if (formWidget.getVerticalHeaderExpression() != null) {
        final Expression verticalHeaderExpression = formWidget.getVerticalHeaderExpression();
        verticalHeaderExpression.setName(
            widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_VERTICAL_HEADER);
        expressionsToEvaluate.add(verticalHeaderExpression);
      } else if (formWidget.getVerticalHeaderExpressionList() != null) {
        final List<Expression> verticalHeaderExpressionList =
            formWidget.getVerticalHeaderExpressionList();
        if (!verticalHeaderExpressionList.isEmpty()) {
          int verticalHeaderExpressionListIndex = 0;
          for (final Expression expression : verticalHeaderExpressionList) {
            expression.setName(
                widgetId
                    + EXPRESSION_KEY_SEPARATOR
                    + WIDGET_VERTICAL_HEADER
                    + verticalHeaderExpressionListIndex);
            expressionsToEvaluate.add(expression);
            verticalHeaderExpressionListIndex++;
          }
        }
      }
      if (formWidget.getHorizontalHeaderExpression() != null) {
        final Expression horizontalHeaderExpression = formWidget.getHorizontalHeaderExpression();
        horizontalHeaderExpression.setName(
            widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_HORIZONTAL_HEADER);
        expressionsToEvaluate.add(horizontalHeaderExpression);
      } else if (formWidget.getHorizontalHeaderExpressionList() != null) {
        final List<Expression> horizontalHeaderExpressionList =
            formWidget.getHorizontalHeaderExpressionList();
        if (!horizontalHeaderExpressionList.isEmpty()) {
          int horizontalHeaderExpressionListIndex = 0;
          for (final Expression expression : horizontalHeaderExpressionList) {
            expression.setName(
                widgetId
                    + EXPRESSION_KEY_SEPARATOR
                    + WIDGET_HORIZONTAL_HEADER
                    + horizontalHeaderExpressionListIndex);
            expressionsToEvaluate.add(expression);
            horizontalHeaderExpressionListIndex++;
          }
        }
      }
    }
    return expressionsToEvaluate;
  }