Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mshabarov opened this issue Mar 18, 2022 · 4 comments
Open

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

mshabarov opened this issue Mar 18, 2022 · 4 comments

Comments

@mshabarov
Copy link
Contributor

  • Description of the bug

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.

  • Minimal reproducible example
  1. Use the render test portlet to reproduce this issue. Go to https://github.com/vaadin/portlet/tree/liferay-test/vaadin-portlet-liferay-integration-tests/liferay-tests-generic/src/main/java/com/vaadin/flow/portal/liferay/rendermodes, build the project and deploy render portlet as well as vaadin-portlet-static into LIferay container.
  2. Add the render portlet to the page and click on the state change buttons shown in the portlet context area.
  • Expected and actual behavior
    Expected: portlet reacts to the state change and it's visual representation should change according to a new state.
    Actual: nothing happens. Portlet only reacts if you change the p_p_state and p_p_mode query parameters manually.

  • Versions:

    • Vaadin Portlet version 1.0.0.beta4
    • Flow version 2.8.3
    • Liferay version 7.4
    • Java version 11
    • OS version Mac OS
    • Browser version (if applicable) Chrome 99
@mshabarov
Copy link
Contributor Author

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 added a commit to vaadin/addressbook-portlet that referenced this issue Mar 29, 2022
@mshabarov
Copy link
Contributor Author

mshabarov commented Mar 30, 2022

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 mshabarov moved this from In progress to Ready To Go in OLD Vaadin Flow ongoing work (Vaadin 10+) Mar 30, 2022
@mshabarov mshabarov removed their assignment Mar 30, 2022
@mshabarov mshabarov moved this from Ready To Go to Product backlog in OLD Vaadin Flow ongoing work (Vaadin 10+) Apr 4, 2022
@mshabarov
Copy link
Contributor Author

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 mshabarov removed the blocked label May 5, 2022
@mshabarov mshabarov moved this from Product backlog to Ready To Go in OLD Vaadin Flow ongoing work (Vaadin 10+) May 11, 2022
@mshabarov mshabarov self-assigned this May 17, 2022
@mshabarov mshabarov moved this from Ready To Go to In progress in OLD Vaadin Flow ongoing work (Vaadin 10+) May 17, 2022
@mshabarov
Copy link
Contributor Author

mshabarov commented May 18, 2022

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.
5. 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.

mshabarov added a commit to vaadin/base-starter-flow-portlet that referenced this issue May 24, 2022
@mshabarov mshabarov moved this from In progress to Product backlog in OLD Vaadin Flow ongoing work (Vaadin 10+) Jun 1, 2022
@mshabarov mshabarov removed their assignment Aug 12, 2022
@mshabarov mshabarov moved this from Product backlog to Parking lot - under consideration in OLD Vaadin Flow ongoing work (Vaadin 10+) Apr 3, 2023
@mshabarov mshabarov removed this from Parking lot - under consideration in OLD Vaadin Flow ongoing work (Vaadin 10+) Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🔖 Normal Priority (P2)
Status: 🅿️Parking lot - under consideration
Development

No branches or pull requests

1 participant