Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-103470

Liferay Forms: url not populated in JSON when a document is selected after being newly uploaded to the document library

    Details

    • Type: Bug
    • Status: Open
    • Resolution: Unresolved
    • Affects Version/s: 7.2.10.1 DXP SP1
    • Fix Version/s: None
    • Component/s: Forms
    • Labels:
      None

      Description

      Problem Background

      Liferay Forms provides the ability for a custom DDMStorageAdapter.save(DDMStorageAdapterSaveRequest) method to save submitted form data, which overrides the default behavior which is to save the data to the Liferay database. The problem is that the url contained within the DDMFormFieldValue JSON text is not populated in JSON when a document is selected after being newly uploaded to the document library.

      Steps to Reproduce

      1. Create a new module with a CustomStorageAdapter that looks like this and deploy the module to $LIFERAY_HOME/osgi/modules:

      CustomStorageAdapter.java
      package com.mycompany;
      
      @Component(
      	immediate = true, property = {"ddm.storage.adapter.type=Custom"},
      	service = DDMStorageAdapter.class
      )
      public class CustomStorageAdapter implements DDMStorageAdapter {
      
      	@Override
      	public DDMStorageAdapterSaveResponse save(
      		DDMStorageAdapterSaveRequest ddmStorageAdapterSaveRequest)
      		throws StorageException {
      
      		DMFormValues ddmFormValues =
      					ddmStorageAdapterSaveRequest.getDDMFormValues();
      
      		Map<String, List<DDMFormFieldValue>> ddmFormFieldValuesMap =
      					ddmFormValues.getDDMFormFieldValuesMap();
      
      		List<DDMFormFieldValue> attachmentFormFieldValues =
      			ddmFormFieldValuesMap.get("attachment");
      
      		for (DDMFormFieldValue attachmentFormFieldValue :
      			attachmentFormFieldValues) {
      
      			Value value = attachmentFormFieldValue.getValue();
      			JSONObject jsonObject = null;
      
      			try {
      				jsonObject = JSONFactoryUtil.createJSONObject(
      					value.getString(value.getDefaultLocale()));
      
      				long fileEntryId = jsonObject.getLong("fileEntryId");
      				String title = jsonObject.getString("title");
      				String url = jsonObject.getString("url");
      
      				System.out.println("fileEntryId=" + fileEntryId +
      					" title=" + title + " url=" + url);
      			}
      			catch (JSONException jsone) {
      				_log.error(jsone.getMessage(), jsone);
      			}
      		}
      
      		return null;
      	}
      
      	@Override
      	public DDMStorageAdapterDeleteResponse delete(
      		DDMStorageAdapterDeleteRequest ddmStorageAdapterDeleteRequest)
      		throws StorageException {
      		return null;
      	}
      
      	@Override
      	public DDMStorageAdapterGetResponse get(
      		DDMStorageAdapterGetRequest ddmStorageAdapterGetRequest)
      		throws StorageException {
      		return null;
      	}
      }
      

      2. Click on "Content & Data -> Forms" in the Control Panel and create a form with a file upload field. Name the field "attachment".

      3. Before hitting the Save button, click the "..." button at the top of the page and then click on "Settings".

      4. Select "Custom" from the dropdown list for the custom storage option.

      5. Disable the autosave.

      6. Set the name of the form to be "MyForm"

      7. Save the form.

      8. Publish the form.

      9. Add the Forms portlet to a portal page and select "MyForm" to be displayed.

      10. Select a file with the file upload control

      11. Upload a new PDF file to the document library

      12. Select the file from the document library

      13. Click on Save in order to submit the form

      Expected Results

      The console output from System.out.println contains a non-null/non-empty relative URL of the submitted file. This is the URL that makes it possible to download the file.

      Actual Results

      The console output from System.out.println contain a null/empty URL for the submitted file.

      Note that when selecting an existing (previously uploaded) file with the document library file selection, the URL field will indeed be populated with a non-null/non-empty value.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              neil.griffin Neil Griffin
              Participants of an Issue:
              Recent user:
              Neil Griffin
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Days since last comment:
                7 weeks, 3 days ago

                Packages

                Version Package