vaadin / portlet

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

Upload component doesn't work with Liferay #195

Closed mshabarov closed 2 years ago

mshabarov commented 2 years ago
        upload.addAttachListener(event -> {
            String target = upload.getElement().getAttribute("target");
            upload.getElement().executeJs("this.setAttribute('target', $0)", target);
        });
mshabarov commented 2 years ago

A similar issue is observed for Anchor and HtmlComponent components, missing attributes are href and data respectively.

mcollovati commented 2 years ago

The problem may be in the client side SimpleElementBindingStrategy.updateAttributeValue method; when handling stream resources in web-component mode the original uri is prepended with configuration.getServiceUrl(). So, for example, the generated target URL http://localhost:8080/web/guest/mytest?p_p_id=ContactForm_WAR_addressbookform_INSTANCE_sjpi&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_resource_id=%2FVAADIN%2Fdynamic%2Fresource%2F0%2Fe423052f-b804-4af5-8873-efaf9c60193e%2Fupload&p_p_cacheability=cacheLevelPage becomes http://localhost:8080/web/guest/mytest?p_p_id=ContactForm_WAR_addressbookform_INSTANCE_sjpi&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_resource_id=%2Fuidl&p_p_cacheability=cacheLevelPage/http://localhost:8080/web/guest/mytest?p_p_id=ContactForm_WAR_addressbookform_INSTANCE_sjpi&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_resource_id=%2FVAADIN%2Fdynamic%2Fresource%2F0%2Fe423052f-b804-4af5-8873-efaf9c60193e%2Fupload&p_p_cacheability=cacheLevelPage.

A quickfix for Liferay problem may be using URL as is on client side, if it is absolute.

String uri = object.getString(NodeProperties.URI_ATTRIBUTE);
if (configuration.isWebComponentMode()) {
    String baseUri = configuration.getServiceUrl();
    baseUri = baseUri.endsWith("/") ? baseUri : baseUri + "/";
    WidgetUtil.updateAttribute(element, attribute,
            baseUri + uri);
} else {
    WidgetUtil.updateAttribute(element, attribute, uri);
}
mcollovati commented 2 years ago

Seems like that handling absolute URL case in SimpleElementBindingStrategy.updateAttributeValue() fixes the problem. Should we move this issue to flow repository? Or better create a new one?

mshabarov commented 2 years ago

@mcollovati thanks for comprehensive analysis. Indeed, as this problem isn't specific for vaadin-portlet and impacts the components whose use StreamResource in web-component mode (embedded), it would be better to fix it on Flow side. I'm closing this ticket in favor of https://github.com/vaadin/flow/issues/13288.