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

Liferay Forms DDMFormValuesSerializer for JSON does not format submitted list entries correctly

    Details

    • Type: Bug
    • Status: Open
    • Resolution: Unresolved
    • Affects Version/s: 7.2.0 GA1, 7.2.10 DXP GA1, 7.2.10 DXP FP1
    • Fix Version/s: None
    • Component/s: Forms
    • Labels:
      None

      Description

      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;
      
      import com.liferay.dynamic.data.mapping.exception.StorageException;
      import com.liferay.dynamic.data.mapping.io.DDMFormValuesSerializer;
      import com.liferay.dynamic.data.mapping.io.DDMFormValuesSerializerSerializeRequest;
      import com.liferay.dynamic.data.mapping.io.DDMFormValuesSerializerSerializeResponse;
      import com.liferay.dynamic.data.mapping.storage.DDMFormValues;
      import com.liferay.dynamic.data.mapping.storage.DDMStorageAdapter;
      import com.liferay.dynamic.data.mapping.storage.DDMStorageAdapterDeleteRequest;
      import com.liferay.dynamic.data.mapping.storage.DDMStorageAdapterDeleteResponse;
      import com.liferay.dynamic.data.mapping.storage.DDMStorageAdapterGetRequest;
      import com.liferay.dynamic.data.mapping.storage.DDMStorageAdapterGetResponse;
      import com.liferay.dynamic.data.mapping.storage.DDMStorageAdapterSaveRequest;
      import com.liferay.dynamic.data.mapping.storage.DDMStorageAdapterSaveResponse;
      import com.liferay.portal.kernel.json.JSONException;
      import com.liferay.portal.kernel.json.JSONFactory;
      import com.liferay.portal.kernel.json.JSONObject;
      import org.osgi.service.component.annotations.Component;
      import org.osgi.service.component.annotations.Reference;
      
      @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 {
      
      		DDMFormValues ddmFormValues =
      			ddmStorageAdapterSaveRequest.getDDMFormValues();
      
      		String submittedJSON = _serializeToDDMJSON(ddmFormValues);
      	
      		JSONObject jsonObject;
      
      		try {
      			jsonObject =
      				_jsonFactory.createJSONObject(submittedJSON);
      		}
      		catch (JSONException e) {
      			throw new StorageException(e);
      		}
      
      		String myListField = jsonObject.getString("myListField");
      
      		System.err.println("**** myListField=" + myListField);
      
      		long primaryKey = System.nanoTime();
      		DDMStorageAdapterSaveResponse.Builder builder =
      			DDMStorageAdapterSaveResponse.Builder.newBuilder(primaryKey);
      
      		return builder.build();
      	}
      
      	private String _serializeToDDMJSON(DDMFormValues ddmFormValues) {
      		DDMFormValuesSerializerSerializeRequest.Builder builder =
      			DDMFormValuesSerializerSerializeRequest.Builder.newBuilder(
      				ddmFormValues);
      
      		DDMFormValuesSerializerSerializeResponse
      			ddmFormValuesSerializerSerializeResponse =
      			_jsonDDMFormValuesSerializer.serialize(builder.build());
      
      		return ddmFormValuesSerializerSerializeResponse.getContent();
      	}
      
      	@Override
      	public DDMStorageAdapterDeleteResponse delete(
      		DDMStorageAdapterDeleteRequest ddmStorageAdapterDeleteRequest)
      		throws StorageException {
      		return null;
      	}
      
      	@Override
      	public DDMStorageAdapterGetResponse get(
      		DDMStorageAdapterGetRequest ddmStorageAdapterGetRequest)
      		throws StorageException {
      		return null;
      	}
      
      	@Reference(unbind = "-")
      	protected void setJSONFactory(JSONFactory jsonFactory) {
      		_jsonFactory = jsonFactory;
      	}
      
      	private JSONFactory _jsonFactory;
      
      	@Reference(target = "(ddm.form.values.serializer.type=json)")
      	private DDMFormValuesSerializer _jsonDDMFormValuesSerializer;
      }
      

      2. Click on "Content & Data -> Forms" in the Control Panel and create a form with a "Select From List" field with three options:
      Foo
      Bar
      Baz

      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. Fill out the form and select Bar from the dropdown list.

      11. Save the form.

      Expected Results:

      The console log contains the following:

      **** myListField=Bar
      

      Actual Results:

      The console log contains the following:

      **** myListField=["Bar"]
      

        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:
                10 weeks ago

                Packages

                Version Package