vaadin / portlet

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

Liferay edit mode: content disappears when moving portlet in another position #211

Open mcollovati opened 2 years ago

mcollovati commented 2 years ago

While editing a Liferay Content Page, when a Vaadin portlet is moved from a position to another its content is no more visible. The issue seems to happen mainly when moving widgets inside layout containers.

To reproduce this bug:

Expected behavior: Portlet content is rendered Actual behavior: Portlet content is not rendered

Versions: Vaadin Portlet version - 1.0.0.beta4 Flow version - 2.7.8 Liferay version - 7.4 Java version - 11

mcollovati commented 2 years ago

At a first glance, it seems like that the problem is that when moving the portlet, a new web-component with a different id is created on the client side and a new server-side Java view component is instantiated. However, in VaadinPortlet.initComponent an already existing PortletViewContext is found, but with a reference to the previous java component instance.

Since the PortletViewContext is found, onPortletViewContextInit is not invoked on the new component, so, if the component tree is built on that method, the result on the client side will be an empty element.

A quick and dirty fix may be to check if context view is the same as the component that is being initialized, and if not create and set a new PortletViewContext, but perhaps it may be worth to do some further investigation.

// if (context == null) { // Actual code
if (context == null || context.getView() != component) { // Fix
    needViewInit = true;
    context = new PortletViewContext(component, portlet.isPortlet3,
            request.getPortletMode(), request.getWindowState());
    portlet.setViewContext(session, namespace, windowName, context);
}