示例#1
0
 protected List<Expression> getExpressionsToEvaluation(
     final List<FormWidget> widgets,
     final Map<String, Serializable> resolvedDisplayExp,
     final Map<String, Object> context) {
   final List<Expression> expressionsToEvaluate = new ArrayList<Expression>();
   for (final FormWidget formWidget : widgets) {
     if (isAuthorized(resolvedDisplayExp, formWidget.getId())) {
       expressionsToEvaluate.addAll(getWidgetExpressions(formWidget, context));
     }
   }
   return expressionsToEvaluate;
 }
示例#2
0
 /**
  * @param formWidget
  * @param evaluatedExpressions
  * @return
  */
 protected Object getFormWidgetInitialValues(
     final FormWidget formWidget, final Map<String, Serializable> evaluatedExpressions) {
   final String widgetId = formWidget.getId();
   Object value = null;
   if (WidgetType.EDITABLE_GRID.equals(formWidget.getType())
       && evaluatedExpressions.containsKey(
           widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_INITIAL_VALUE + 0 + INDEX_SEPARATOR + 0)) {
     final List<List<Object>> initialValue = new ArrayList<List<Object>>();
     int initialValueRowIndex = 0;
     do {
       final List<Object> initialValueRow = new ArrayList<Object>();
       int initialValueColumnIndex = 0;
       do {
         final Object initialValueCell =
             evaluatedExpressions.get(
                 widgetId
                     + EXPRESSION_KEY_SEPARATOR
                     + WIDGET_INITIAL_VALUE
                     + initialValueRowIndex
                     + INDEX_SEPARATOR
                     + initialValueColumnIndex);
         initialValueRow.add(initialValueCell);
         initialValueColumnIndex++;
       } while (evaluatedExpressions.containsKey(
           widgetId
               + EXPRESSION_KEY_SEPARATOR
               + WIDGET_INITIAL_VALUE
               + initialValueRowIndex
               + INDEX_SEPARATOR
               + initialValueColumnIndex));
       initialValue.add(initialValueRow);
       initialValueRowIndex++;
     } while (evaluatedExpressions.containsKey(
         widgetId
             + EXPRESSION_KEY_SEPARATOR
             + WIDGET_INITIAL_VALUE
             + initialValueRowIndex
             + INDEX_SEPARATOR
             + 0));
     value = initialValue;
   } else {
     value = evaluatedExpressions.get(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_INITIAL_VALUE);
   }
   return value;
 }
示例#3
0
 /**
  * Add the widget value to evaluate to the Map of expression to evaluated
  *
  * @param formWidget the widget
  * @param expressionsToEvaluate the list of expressions to evaluate
  * @param context the context including the URL parameters
  */
 protected void addFormWidgetValueExpressionToEvaluate(
     final FormWidget formWidget,
     final List<Expression> expressionsToEvaluate,
     final Map<String, Object> context) {
   if (formWidget.getInitialValueExpression() != null) {
     final Expression expression = formWidget.getInitialValueExpression();
     expression.setName(formWidget.getId() + EXPRESSION_KEY_SEPARATOR + WIDGET_INITIAL_VALUE);
     expressionsToEvaluate.add(expression);
   } else if (WidgetType.EDITABLE_GRID.equals(formWidget.getType())
       && formWidget.getInitialValueExpressionArray() != null) {
     final List<List<Expression>> expressionArray = formWidget.getInitialValueExpressionArray();
     if (!expressionArray.isEmpty()) {
       int expressionArrayRowIndex = 0;
       for (final List<Expression> expressionArrayRow : expressionArray) {
         int expressionArrayIndex = 0;
         for (final Expression expression : expressionArrayRow) {
           expression.setName(
               formWidget.getId()
                   + EXPRESSION_KEY_SEPARATOR
                   + WIDGET_INITIAL_VALUE
                   + expressionArrayRowIndex
                   + INDEX_SEPARATOR
                   + expressionArrayIndex);
           expressionsToEvaluate.add(expression);
           expressionArrayIndex++;
         }
         expressionArrayRowIndex++;
       }
     }
   }
 }
示例#4
0
 /**
  * @param formWidget
  * @param evaluatedExpressions
  */
 protected void setFormWidgetAvailableValues(
     final FormWidget formWidget, final Map<String, Serializable> evaluatedExpressions) {
   final Object availableValuesObject =
       evaluatedExpressions.get(
           formWidget.getId() + EXPRESSION_KEY_SEPARATOR + WIDGET_AVAILABLE_VALUES);
   if (availableValuesObject != null) {
     if (formWidget.getType().equals(WidgetType.TABLE)) {
       final List<List<ReducedFormFieldAvailableValue>> availableValues =
           getTableAvailableValues(availableValuesObject, formWidget.getId());
       formWidget.setReducedTableAvailableValues(availableValues);
     } else {
       final List<ReducedFormFieldAvailableValue> availableValues =
           getAvailableValues(availableValuesObject, formWidget.getId());
       formWidget.setReducedAvailableValues(availableValues);
     }
   } else {
     setAvailableValuesListsAndArrays(formWidget, evaluatedExpressions);
   }
 }
示例#5
0
 /**
  * Set the tables parameters
  *
  * @param formWidget the widget
  * @param evaluatedExpressions the map of evaluated expressions
  * @param context the context including the URL parameters
  * @throws FormNotFoundException
  * @throws FormServiceProviderNotFoundException
  */
 @SuppressWarnings("unchecked")
 public void setTablesParams(
     final FormWidget formWidget,
     final Map<String, Serializable> evaluatedExpressions,
     final Map<String, Object> context)
     throws FormNotFoundException, FormServiceProviderNotFoundException {
   final String widgetId = formWidget.getId();
   if (WidgetType.TABLE.equals(formWidget.getType())
       || WidgetType.EDITABLE_GRID.equals(formWidget.getType())) {
     final Object valueColumnIndex =
         evaluatedExpressions.get(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_VALUE_COLUMN_INDEX);
     if (valueColumnIndex != null) {
       try {
         formWidget.setValueColumnIndex((Integer) valueColumnIndex);
       } catch (final Exception e) {
         if (LOGGER.isLoggable(Level.WARNING)) {
           LOGGER.log(
               Level.WARNING,
               "The max number of columns has to be set with an integer or a groovy expression returning an integer.");
         }
         formWidget.setValueColumnIndex(0);
       }
     }
     final Object maxColumns =
         evaluatedExpressions.get(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_MAX_COLUMNS);
     if (maxColumns != null) {
       try {
         formWidget.setMaxColumns((Integer) maxColumns);
       } catch (final Exception e) {
         if (LOGGER.isLoggable(Level.WARNING)) {
           LOGGER.log(
               Level.WARNING,
               "The max number of columns has to be set with an integer or a groovy expression returning an integer.");
         }
         formWidget.setMaxColumns(-1);
       }
     } else {
       formWidget.setMaxColumns(-1);
     }
     final Object minColumns =
         evaluatedExpressions.get(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_MIN_COLUMNS);
     if (minColumns != null) {
       try {
         formWidget.setMinColumns((Integer) minColumns);
       } catch (final Exception e) {
         if (LOGGER.isLoggable(Level.WARNING)) {
           LOGGER.log(
               Level.WARNING,
               "The min number of columns has to be set with an integer or a groovy expression returning an integer.");
         }
         formWidget.setMinColumns(-1);
       }
     } else {
       formWidget.setMinColumns(-1);
     }
     final Object maxRows =
         evaluatedExpressions.get(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_MAX_ROWS);
     if (maxRows != null) {
       try {
         formWidget.setMaxRows((Integer) maxRows);
       } catch (final Exception e) {
         if (LOGGER.isLoggable(Level.WARNING)) {
           LOGGER.log(
               Level.WARNING,
               "The max number of rows has to be set with an integer or a groovy expression returning an integer.");
         }
         formWidget.setMaxRows(-1);
       }
     } else {
       formWidget.setMaxRows(-1);
     }
     final Object minRows =
         evaluatedExpressions.get(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_MIN_ROWS);
     if (minRows != null) {
       try {
         formWidget.setMinRows((Integer) minRows);
       } catch (final Exception e) {
         if (LOGGER.isLoggable(Level.WARNING)) {
           LOGGER.log(
               Level.WARNING,
               "The max number of rows has to be set with an integer or a groovy expression returning an integer.");
         }
         formWidget.setMinRows(-1);
       }
     } else {
       formWidget.setMinRows(-1);
     }
     final Object verticalHeader =
         evaluatedExpressions.get(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_VERTICAL_HEADER);
     List<String> verticalHeaderList = null;
     if (verticalHeader != null) {
       try {
         verticalHeaderList = new ArrayList<String>((Collection<String>) verticalHeader);
       } catch (final ClassCastException e) {
         if (LOGGER.isLoggable(Level.SEVERE)) {
           LOGGER.log(
               Level.SEVERE,
               "The vertical header expression for widget "
                   + formWidget.getId()
                   + " should return a Collection.",
               e);
         }
       }
     } else if (evaluatedExpressions.containsKey(
         widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_VERTICAL_HEADER + 0)) {
       verticalHeaderList = new ArrayList<String>();
       int verticalHeaderIndex = 0;
       do {
         final Object verticalHeaderCell =
             evaluatedExpressions.get(
                 widgetId
                     + EXPRESSION_KEY_SEPARATOR
                     + WIDGET_VERTICAL_HEADER
                     + verticalHeaderIndex);
         try {
           verticalHeaderList.add((String) verticalHeaderCell);
         } catch (final ClassCastException e) {
           if (LOGGER.isLoggable(Level.SEVERE)) {
             LOGGER.log(
                 Level.SEVERE,
                 "All the vertical header expressions for widget "
                     + formWidget.getId()
                     + " should return a String.",
                 e);
           }
         }
         verticalHeaderIndex++;
       } while (evaluatedExpressions.containsKey(
           widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_VERTICAL_HEADER + verticalHeaderIndex));
     }
     formWidget.setVerticalHeader(verticalHeaderList);
     final Object horizontalHeader =
         evaluatedExpressions.get(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_HORIZONTAL_HEADER);
     List<String> horizontalHeaderList = null;
     if (horizontalHeader != null) {
       try {
         horizontalHeaderList = new ArrayList<String>((Collection<String>) horizontalHeader);
       } catch (final ClassCastException e) {
         if (LOGGER.isLoggable(Level.SEVERE)) {
           LOGGER.log(
               Level.SEVERE,
               "The horizontal header expression for widget "
                   + formWidget.getId()
                   + " should return a Collection.",
               e);
         }
       }
     } else if (evaluatedExpressions.containsKey(
         widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_HORIZONTAL_HEADER + 0)) {
       horizontalHeaderList = new ArrayList<String>();
       int horizontalHeaderIndex = 0;
       do {
         final Object horizontalHeaderCell =
             evaluatedExpressions.get(
                 widgetId
                     + EXPRESSION_KEY_SEPARATOR
                     + WIDGET_HORIZONTAL_HEADER
                     + horizontalHeaderIndex);
         try {
           horizontalHeaderList.add((String) horizontalHeaderCell);
         } catch (final ClassCastException e) {
           if (LOGGER.isLoggable(Level.SEVERE)) {
             LOGGER.log(
                 Level.SEVERE,
                 "All the horizontal header expressions for widget "
                     + formWidget.getId()
                     + " should return a String.",
                 e);
           }
         }
         horizontalHeaderIndex++;
       } while (evaluatedExpressions.containsKey(
           widgetId
               + EXPRESSION_KEY_SEPARATOR
               + WIDGET_HORIZONTAL_HEADER
               + horizontalHeaderIndex));
     }
     formWidget.setHorizontalHeader(horizontalHeaderList);
   }
 }
示例#6
0
 /**
  * @param formWidget
  * @param evaluatedExpressions
  */
 protected void setAvailableValuesListsAndArrays(
     final FormWidget formWidget, final Map<String, Serializable> evaluatedExpressions) {
   final String widgetId = formWidget.getId();
   if (WidgetType.TABLE.equals(formWidget.getType())) {
     if (evaluatedExpressions.containsKey(
         widgetId
             + EXPRESSION_KEY_SEPARATOR
             + WIDGET_AVAILABLE_VALUE_VALUE
             + 0
             + INDEX_SEPARATOR
             + 0)) {
       int availableValueRowIndex = 0;
       do {
         int availableValueColumnIndex = 0;
         do {
           final Object availableValuelabel =
               evaluatedExpressions.get(
                   widgetId
                       + EXPRESSION_KEY_SEPARATOR
                       + WIDGET_AVAILABLE_VALUE_LABEL
                       + availableValueRowIndex
                       + INDEX_SEPARATOR
                       + availableValueColumnIndex);
           final Object availableValueValue =
               evaluatedExpressions.get(
                   widgetId
                       + EXPRESSION_KEY_SEPARATOR
                       + WIDGET_AVAILABLE_VALUE_VALUE
                       + availableValueRowIndex
                       + INDEX_SEPARATOR
                       + availableValueColumnIndex);
           final FormFieldAvailableValue availableValue =
               formWidget
                   .getTableAvailableValues()
                   .get(availableValueRowIndex)
                   .get(availableValueColumnIndex);
           availableValue.setLabel(getStringValue(availableValuelabel));
           availableValue.setValue(getStringValue(availableValueValue));
           availableValueColumnIndex++;
         } while (evaluatedExpressions.containsKey(
             widgetId
                 + EXPRESSION_KEY_SEPARATOR
                 + WIDGET_AVAILABLE_VALUE_VALUE
                 + availableValueRowIndex
                 + INDEX_SEPARATOR
                 + availableValueColumnIndex));
         availableValueRowIndex++;
       } while (evaluatedExpressions.containsKey(
           widgetId
               + EXPRESSION_KEY_SEPARATOR
               + WIDGET_AVAILABLE_VALUE_VALUE
               + availableValueRowIndex
               + INDEX_SEPARATOR
               + 0));
     }
   } else {
     if (evaluatedExpressions.containsKey(
         widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_AVAILABLE_VALUE_VALUE + 0)) {
       int availableValueIndex = 0;
       do {
         final Object availableValuelabel =
             evaluatedExpressions.get(
                 widgetId
                     + EXPRESSION_KEY_SEPARATOR
                     + WIDGET_AVAILABLE_VALUE_LABEL
                     + availableValueIndex);
         final Object availableValueValue =
             evaluatedExpressions.get(
                 widgetId
                     + EXPRESSION_KEY_SEPARATOR
                     + WIDGET_AVAILABLE_VALUE_VALUE
                     + availableValueIndex);
         final FormFieldAvailableValue availableValue =
             formWidget.getAvailableValues().get(availableValueIndex);
         availableValue.setLabel(getStringValue(availableValuelabel));
         availableValue.setValue(getStringValue(availableValueValue));
         availableValueIndex++;
       } while (evaluatedExpressions.containsKey(
           widgetId
               + EXPRESSION_KEY_SEPARATOR
               + WIDGET_AVAILABLE_VALUE_VALUE
               + availableValueIndex));
     }
   }
 }
示例#7
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);
    }
  }
示例#8
0
 /** @param formWidget */
 protected void addFormWidgetAvailableValuesExpressions(
     final FormWidget formWidget, final List<Expression> expressionsToEvaluate) {
   final String widgetId = formWidget.getId();
   if (formWidget.getAvailableValuesExpression() != null
       && !WidgetType.SUGGESTBOX_ASYNC.equals(formWidget.getType())) {
     final Expression availableValuesExpression = formWidget.getAvailableValuesExpression();
     availableValuesExpression.setName(
         widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_AVAILABLE_VALUES);
     expressionsToEvaluate.add(availableValuesExpression);
   } else {
     if (WidgetType.TABLE.equals(formWidget.getType())) {
       final List<List<FormFieldAvailableValue>> tableAvailableValues =
           formWidget.getTableAvailableValues();
       if (tableAvailableValues != null && !tableAvailableValues.isEmpty()) {
         int availableValueRowIndex = 0;
         for (final List<FormFieldAvailableValue> formFieldAvailableValuesRow :
             tableAvailableValues) {
           int availableValueIndex = 0;
           for (final FormFieldAvailableValue formFieldAvailableValue :
               formFieldAvailableValuesRow) {
             final Expression availableValueLabelExpression =
                 formFieldAvailableValue.getLabelExpression();
             availableValueLabelExpression.setName(
                 widgetId
                     + EXPRESSION_KEY_SEPARATOR
                     + WIDGET_AVAILABLE_VALUE_LABEL
                     + availableValueRowIndex
                     + INDEX_SEPARATOR
                     + availableValueIndex);
             expressionsToEvaluate.add(availableValueLabelExpression);
             final Expression availableValueValueExpression =
                 formFieldAvailableValue.getValueExpression();
             availableValueValueExpression.setName(
                 widgetId
                     + EXPRESSION_KEY_SEPARATOR
                     + WIDGET_AVAILABLE_VALUE_VALUE
                     + availableValueRowIndex
                     + INDEX_SEPARATOR
                     + availableValueIndex);
             expressionsToEvaluate.add(availableValueValueExpression);
             availableValueIndex++;
           }
           availableValueRowIndex++;
         }
       }
     } else {
       final List<FormFieldAvailableValue> availableValues = formWidget.getAvailableValues();
       if (availableValues != null && !availableValues.isEmpty()) {
         int availableValueIndex = 0;
         for (final FormFieldAvailableValue formFieldAvailableValue : availableValues) {
           final Expression availableValueLabelExpression =
               formFieldAvailableValue.getLabelExpression();
           availableValueLabelExpression.setName(
               widgetId
                   + EXPRESSION_KEY_SEPARATOR
                   + WIDGET_AVAILABLE_VALUE_LABEL
                   + availableValueIndex);
           expressionsToEvaluate.add(availableValueLabelExpression);
           final Expression availableValueValueExpression =
               formFieldAvailableValue.getValueExpression();
           availableValueValueExpression.setName(
               widgetId
                   + EXPRESSION_KEY_SEPARATOR
                   + WIDGET_AVAILABLE_VALUE_VALUE
                   + availableValueIndex);
           expressionsToEvaluate.add(availableValueValueExpression);
           availableValueIndex++;
         }
       }
     }
   }
 }
示例#9
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;
  }
示例#10
0
 protected FormFieldValue getFieldNullValue(final FormWidget formWidget) {
   FormFieldValue fieldValue = null;
   if (formWidget.getType().equals(WidgetType.CHECKBOX)) {
     fieldValue = new FormFieldValue(Boolean.FALSE, Boolean.class.getName());
   } else if (formWidget.getType().equals(WidgetType.LISTBOX_SIMPLE)
       || formWidget.getType().equals(WidgetType.RADIOBUTTON_GROUP)) {
     if (formWidget.getAvailableValues() != null && formWidget.getAvailableValues().size() > 0) {
       fieldValue =
           new FormFieldValue(
               formWidget.getAvailableValues().get(0).getValue(), String.class.getName());
     } else {
       fieldValue = new FormFieldValue("", String.class.getName());
     }
   } else if (formWidget.getType().equals(WidgetType.DATE)) {
     String formatPattern = null;
     if (formWidget.getDisplayFormat() != null && formWidget.getDisplayFormat().length() > 0) {
       formatPattern = formWidget.getDisplayFormat();
     } else {
       formatPattern = defaultDateFormatPattern;
     }
     fieldValue = new FormFieldValue(null, Date.class.getName(), formatPattern);
   } else if (formWidget.getType().equals(WidgetType.DURATION)) {
     fieldValue = new FormFieldValue(Long.valueOf(0), Long.class.getName());
   } else {
     fieldValue = new FormFieldValue(null, Serializable.class.getName());
   }
   return fieldValue;
 }
示例#11
0
 protected void storeWidgetInCacheAndSetCacheID(
     final FormCacheUtil formCacheUtil,
     final String formID,
     final String pageID,
     final String locale,
     final Date processDeployementDate,
     final FormWidget formWidget) {
   if (isExpressionDynamic(formWidget.getInitialValueExpression())
       || isArrayOfExpressionsDynamic(formWidget.getInitialValueExpressionArray())
       || isExpressionDynamic(formWidget.getAvailableValuesExpression())
       || isListOfExpressionsDynamic(formWidget.getAvailableValues())
       || isListOfListOfExpressionsDynamic(formWidget.getTableAvailableValues())
       || isExpressionDynamic(formWidget.getDisplayConditionExpression())) {
     formWidget.setHasDynamicValue(true);
   }
   final String formWidgetCacheId =
       formCacheUtil.storeFormWidget(formID, pageID, locale, processDeployementDate, formWidget);
   formWidget.setFormWidgetCacheId(formWidgetCacheId);
   if (formWidget.getValidators() != null) {
     formWidget.setValidatorsCacheId(
         formCacheUtil.storeFieldValidators(
             formID,
             pageID,
             formWidget.getId(),
             locale,
             processDeployementDate,
             formWidget.getValidators()));
   }
 }
示例#12
0
 /**
  * Build a field value object from the process definition
  *
  * @param value the value retrieved from the engine
  * @param formWidget the {@link FormWidget} associated with this field value
  * @return a {@link FormFieldValue} object
  */
 public FormFieldValue getFieldValue(
     final Object value, final FormWidget formWidget, final Locale locale) {
   FormFieldValue fieldValue = null;
   if (value != null) {
     // deals with the types whose corresponding form fields
     // input and output value is not a string
     if (value instanceof Date) {
       String formatPattern = null;
       if (formWidget.getDisplayFormat() != null && formWidget.getDisplayFormat().length() > 0) {
         formatPattern = formWidget.getDisplayFormat();
       } else {
         formatPattern = defaultDateFormatPattern;
       }
       fieldValue = new FormFieldValue((Date) value, Date.class.getName(), formatPattern);
     } else if (value instanceof Collection<?>) {
       // perform several levels of toString on the items of the collection
       fieldValue =
           new FormFieldValue(
               (Serializable) processCollectionValue(value), Collection.class.getName());
     } else if (value instanceof String && formWidget.getType().equals(WidgetType.DATE)) {
       final String valueStr = (String) value;
       String formatPattern = null;
       if (formWidget.getDisplayFormat() != null && formWidget.getDisplayFormat().length() > 0) {
         formatPattern = formWidget.getDisplayFormat();
       } else {
         formatPattern = defaultDateFormatPattern;
       }
       Date dateValue = null;
       if (valueStr.length() > 0) {
         try {
           final DateFormat dateFormat = new SimpleDateFormat(formatPattern, locale);
           dateValue = dateFormat.parse(valueStr);
         } catch (final ParseException e) {
           if (LOGGER.isLoggable(Level.SEVERE)) {
             LOGGER.log(
                 Level.SEVERE,
                 "The initial value for widget "
                     + formWidget.getId()
                     + " is not consistent with the pattern "
                     + formatPattern,
                 e);
           }
         }
       }
       fieldValue = new FormFieldValue(dateValue, Date.class.getName(), formatPattern);
     } else if (value instanceof String && formWidget.getType().equals(WidgetType.CHECKBOX)) {
       Boolean booleanValue = null;
       try {
         booleanValue = Boolean.parseBoolean((String) value);
       } catch (final Exception e) {
         if (LOGGER.isLoggable(Level.SEVERE)) {
           LOGGER.log(
               Level.SEVERE,
               "The initial value for widget "
                   + formWidget.getId()
                   + " is not consistent with a boolean.",
               e);
         }
         booleanValue = Boolean.valueOf(false);
       }
       fieldValue = new FormFieldValue(booleanValue, Boolean.class.getName());
     } else if (value instanceof Serializable) {
       fieldValue = new FormFieldValue((Serializable) value, value.getClass().getName());
     } else {
       fieldValue = new FormFieldValue(value.toString(), String.class.getName());
     }
   } else {
     fieldValue = getFieldNullValue(formWidget);
   }
   return fieldValue;
 }