vaadin / portlet

Portlet support for Vaadin Flow
https://vaadin.com
Other
2 stars 3 forks source link

Setting a render state with Portlet Hub doesn't work with Liferay #214

Open mshabarov opened 2 years ago

mshabarov commented 2 years ago

PortletViewContext::setWindowState and PortletViewContext::setPortletMode do not work with LIferay. When the Hub API is called hub.setRenderState(state); nothing happens and no exception or console errors are shown.

mshabarov commented 2 years ago

Liferay implementation of Portlet Hub API doesn't do anything when PortletInit::setRenderState is called on the client side.

When the service-side code is running

@Override
    public void onPortletViewContextInit(PortletViewContext context) {
             context.setWindowState(WindowState.MAXIMIZED);
    }

it then triggers window.Vaadin.Flow.Portlets.setPortletState() on the client side. Then it calls PortletInit::setRenderState in turn. But this API does not do anything regarding portlet rendering change. Visually portlet remains the same and the state is the same.

If I open the browser console and execute:

newstate = window.portlet.data.pageRenderState.portlets["_render_WAR_liferaytestsgeneric_INSTANCE_xfIl2IrfY46A_"].state

newstate.portletMode = 'edit'

window.portlet.data.pageRenderState.portlets["_render_WAR_liferaytestsgeneric_INSTANCE_xfIl2IrfY46A_"].state = newstate

nothing happens. So either something isn't set up in vaadin-portlet, or it's a bug in Liferay.

mshabarov commented 2 years ago

Issue created in the Liferay's Issue tracker https://issues.liferay.com/browse/LPS-150560. Further development is blocked until we get more information from Liferay experts.

mshabarov commented 2 years ago

Here is a feedback from Liferay (5.05.2022):

We debugged the case further, mainly the JS files in the browser console, and our current observation is that when executing the state change either by clicking on the "Maximize/Normalize" buttons or the "To view mode/To edit mode" buttons, the code execution enters a poller method in Vaadin's PortletMethod.js file (around line 19), which seem to distrupt the execution. Therefore the code never finishes the setRenderState method in Liferay's PortletInit.es.js.

More specifially, in the setRenderState the validateState(state, portletData); line is never reached:

setRenderState(state) {
    validateArguments(arguments, 1, 1, ['object']);

    if (
 pageRenderState.portlets &&
 pageRenderState.portlets[this._portletId]
    ) {
 const portletData = pageRenderState.portlets[this._portletId];

 validateState(state, portletData);
 this._updateState(state);
    }
}

Based on this observation, we currently suspect that the root cause might lay in Vaadin's code. As debugging the Vaadin code further falls out of Support's scope, we would like to kindly ask you to debug the case further on your side. If you still suspect that the problem is on our side, we kindly ask you to explain your findings in details.

Many Thanks, Zalan

mshabarov commented 2 years ago

The investigation was fulfilled on the impact of "poller" function on the state validation method. Answer sent to Liferay expert:

  1. I removed the "poller" function from "PortletMethods.js", so that my method looked as follows:
    window.Vaadin.Flow.Portlets.executeWhenHubIdle = function (hub, task) {
         task(hub);
    };
  1. I rebuilt my test portlet with this patched vaadin-portlet artifact and deployed it to Liferay.

  2. When I changed the state by clicking "Maximize"/"Normalize" or "To edit mode"/"To view mode", nothing was changed as previously. (see attached screenshot)

  3. I noticed another observation: if I have only "view" mode in my portlet.xml, as follows:

        <supports>
            <mime-type>text/html</mime-type>
            <portlet-mode>view</portlet-mode>
        </supports>

    then I got the following exception in browser console:

    The error has occurred in the JS code: '$0, return (function() { window.Vaadin.Flow.Portlets.setPortletState('_MyPortlet1_WAR_portletstarter_', 'normal', 'edit', false);}).apply($0)'
    Uncaught TypeError: Invalid portletMode=edit is not in ["view"]
    at t.validateState 
    at g.setRenderState 
    at PortletMethods.js:43:17 
    at Object.window.Vaadin.Flow.Portlets.executeWhenHubIdle (PortletMethods.js:29:10)
    at Object.window.Vaadin.Flow.Portlets.setPortletState (PortletMethods.js:39:37) 

    so the state validation on the "PortletInit.es.js" side is fulfiled. once I add "edit" portlet mode to the portlet.xml, no error is thrown, so the validation passes.

  4. Seems that the "poller" function has nothing to do with this issue, because even if I remove it, the Liferay doesn't react on "setRenderState(state)" method.

Hope my explanations are clear. If needed, I can send the portlet war with no poller function for testing (it weights around 50 mb though). Please share your thoughts. At the moment I don't see how can I fix it on Vaadin side.