0

How to update / refresh Editor Area from custom Editor in Hybris?

public class CustomEditor extends AbstractComponentWidgetAdapterAware implements CockpitEditorRenderer<Object> {

    @Override
    public void render(Component parent, EditorContext<Object> editorContext, EditorListener<Object> editorListener) {
        Button button = new Button("Click");
        button.addEventListener("onClick", (event) -> {
            //some logic
            //update the Editor Area after logic is done?
        });
        parent.appendChild(button);
    }
}
Sali Manaf
  • 166
  • 1
  • 9

2 Answers2

1

you need to used the passed listener to inform the model on the changed value. For example:

public class CustomEditor extends AbstractComponentWidgetAdapterAware implements CockpitEditorRenderer<Object> {

@Override
public void render(Component parent, EditorContext<Object> editorContext, EditorListener<Object> editorListener) {
    Button button = new Button("Click");
    button.addEventListener("onClick", (event) -> {
        //some logic
        editorListener.onValueChanged(result);
    });
    parent.appendChild(button);
}

}

I hope that helps!

Wojtek
  • 111
  • 4
  • Thank you for the provided solution. For my case this is a partial solution. What i want to achieve is similar to editor action buttons (to reload / refresh the editor area content) In the action buttons it can be done with setting status flag "OBJECT_MODIFIED" – Sali Manaf Sep 17 '19 at 09:27
  • In order to refresh actions you would need to update the object on which the actions listen. If you are sure the editor will only be used in the Editor Area you may try to use model attributes "valueChanged" (boolean) or "currentObject" and try to set them from code. In general this is not how you should implement editors while it kills the ability to use them all across the application. The hint is not checked, you need to verify if you can access the model directly from the editor. – Wojtek Sep 18 '19 at 08:41
0

You can use widget connection for this

    <widget-connection sourceWidgetId="myCustomWidget" targetWidgetId="editorArea"
             outputId="myItemType" inputId="inputObject"/>

Hope it helps!

www.hybriscx.com
  • 1,129
  • 4
  • 22