コード例 #1
0
  /** @see org.opencms.workplace.CmsWidgetDialog#validateParamaters() */
  @Override
  protected void validateParamaters() throws Exception {

    if (CmsStringUtil.isEmptyOrWhitespaceOnly(m_paramEntryid)
        || CmsStringUtil.isEmptyOrWhitespaceOnly(m_paramFormid)) {
      throw new Exception();
    }
    m_formData = CmsFormDataAccess.getInstance().readForm(Integer.parseInt(m_paramEntryid));
  }
コード例 #2
0
  /**
   * Creates the dynamic widgets for the current submitted data for each field.
   *
   * <p>
   *
   * @throws Exception if something goes wrong
   */
  private void addDynamicWidgets() throws Exception {

    if (m_fields == null) {
      m_fields = new HashMap<String, CmsFormDataEditBean>();
    }

    // get the list of all fields
    List<String> columnNames =
        CmsFormDataAccess.getInstance().readFormFieldNames(m_paramFormid, 0, Long.MAX_VALUE);

    // determine if the columns can be edited by the current user
    boolean editable;
    try {
      CmsResource formFile = getCms().readResource(m_formData.getResourceId());
      editable =
          OpenCms.getRoleManager().hasRole(getCms(), CmsRole.DATABASE_MANAGER)
              || getCms()
                  .hasPermissions(
                      formFile, CmsPermissionSet.ACCESS_WRITE, false, CmsResourceFilter.ALL);
    } catch (CmsException e) {
      // error reading form resource, only check roles of current user
      editable = OpenCms.getRoleManager().hasRole(getCms(), CmsRole.DATABASE_MANAGER);
    }

    String uploadFolder =
        OpenCms.getModuleManager()
            .getModule(CmsForm.MODULE_NAME)
            .getParameter(CmsForm.MODULE_PARAM_UPLOADFOLDER, WEBFORM_UPLOADFOLDER_NONE);

    // for each column create a widget
    String column;
    String value;
    CmsFormDataEditBean edit;
    for (int i = 0; i < columnNames.size(); i++) {

      // get the entry and fill the columns
      column = columnNames.get(i);
      value = m_formData.getFieldValue(column);
      if (CmsStringUtil.isEmpty(value)) {
        value = "";
      }
      edit = createEditEntry(value, uploadFolder, editable);
      addWidget(
          new CmsWidgetDialogParameter(
              edit, "value", column, "", PAGES[0], edit.getWidget(), 0, 1));
      m_fields.put(column, edit);
    }
  }
コード例 #3
0
  /** @see org.opencms.workplace.CmsWidgetDialog#actionCommit() */
  @Override
  public void actionCommit() {

    List<Exception> errors = new ArrayList<Exception>();
    try {
      // get the list of all fields
      List<String> columnNames =
          CmsFormDataAccess.getInstance().readFormFieldNames(m_paramFormid, 0, Long.MAX_VALUE);

      // for each field look if the value has changed and update the database
      String column = null;
      CmsFormDataEditBean data;
      String value = null;
      String orgValue;
      for (int i = 0; i < columnNames.size(); i++) {
        try {
          // get for the field the old and new value
          column = columnNames.get(i);
          data = m_fields.get(column);
          orgValue = m_formData.getFieldValue(column);
          value = data.getValue();
          if (LOG.isDebugEnabled()) {
            LOG.debug(
                Messages.get()
                    .getBundle()
                    .key(
                        Messages.LOG_COMPARE_FORM_FIELDS_4,
                        new String[] {column, value, orgValue, m_paramEntryid}));
          }

          // compares the old and new value and update the database if not identical
          if (!compareValues(orgValue, value)
              || ((value != null) && (value.trim().length() == 0))) {
            CmsFormDataAccess.getInstance()
                .updateFieldValue(Integer.parseInt(m_paramEntryid), column, value);
            if (LOG.isDebugEnabled()) {
              LOG.debug(
                  Messages.get()
                      .getBundle()
                      .key(Messages.LOG_WRITE_FORM_FIELDS_3, column, value, m_paramEntryid));
            }
          }
        } catch (Exception e) {
          if (LOG.isErrorEnabled()) {
            LOG.error(
                Messages.get()
                    .getBundle()
                    .key(Messages.ERR_WRITE_FORM_FIELDS_3, column, value, m_paramEntryid));
          }
          errors.add(
              new CmsException(
                  Messages.get()
                      .container(Messages.ERR_WRITE_FORM_FIELDS_3, column, value, m_paramEntryid)));
        }
      }
    } catch (Exception ex) {
      errors.add(ex);
    }
    // set the list of errors to display when saving failed
    setCommitErrors(errors);
  }