Backoffice : CSV Upload Functionality in Editor Area

694 Views Asked by At

SAP Commerce 1811

I have one custom type e.g. "CustomType" which has one media attribute of type MediaModel. My requirement is to upload CSV media using Drag & Drop Editor in Editor Area.

So i used OOTB com.hybris.cockpitng.editor.dndfileupload of type com.hybris.cockpitng.editor.defaultfileupload.FileUploadResult and apply on my media attribute.

<attribute type="com.hybris.cockpitng.editor.defaultfileupload.FileUploadResult" editor="com.hybris.cockpitng.editor.dndfileupload" qualifier="media">
           <editor-parameter>
              <name>accept</name>
              <value>text/csv</value>
           </editor-parameter>
</attribute>

Now i created one custom Backoffice action e.g. "UploadMedia" and configured in editorareaactions of "CustomType".

As in when i upload csv media and click on my action, In my Action Controller, I am trying to fetch uploaded FileUploadResult media but its always giving null value.

@Override
public ActionResult<Object> perform(final ActionContext<TargetGroupModel> ctx)
{
    final WidgetModel model = (WidgetModel) ctx.getParameter(ActionContext.PARENT_WIDGET_MODEL);
    if (model != null)
    {
        final FileUploadResult result = model.getValue("currentObject.media", FileUploadResult.class);
        System.out.println(result.getData()); // result is always NULL
    }

    return new ActionResult<>(ActionResult.SUCCESS);
}

And the strange thing is, while on debug, if i inspect the WidgetModel, i can see for this key "currentObject.media", value is there.

Any help ?

1

There are 1 best solutions below

0
On BEST ANSWER

I solved the issue by just typecast ctx.getParameter(ActionContext.PARENT_WIDGET_MODEL) with Map and get the value with currentObject.media Key.

Working Code

@Override
public ActionResult<Object> perform(final ActionContext<TargetGroupModel> ctx)
{
    final Map map = (Map) ctx.getParameter(ActionContext.PARENT_WIDGET_MODEL);
    if (map != null)
    {
       final FileUploadResult result = map.get("currentObject.media");
       System.out.println(result.getData());
    }

    return new ActionResult<>(ActionResult.SUCCESS);
}