Skip to content

Commit

Permalink
fix: Load the portlet methods file from a jar resources
Browse files Browse the repository at this point in the history
Uses portlet context and loads the portlet methods file from jar dependency resources instead of static bundle for Pluto 3.0 implementations except Liferay.

Fixes #191
  • Loading branch information
mshabarov authored and caalador committed Jan 14, 2022
1 parent 76b695e commit 5a70934
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

/**
* VaadinPortlet workarounds for Liferay versions 7.2.x and 7.3.x
*
*
* Requires the implementing portlet to signal PortletHub dependency due to a Liferay bug.
* Addresses inconsistent behaviour in injecting required Vaadin specific javascript.
*/
Expand Down Expand Up @@ -48,7 +48,7 @@ protected void doHeaders(RenderRequest request, RenderResponse response)
* 1. The script tag will appear once per portlet
* 2. Liferay partial page update breaks the page and causes Vaadin components to render blank
* *if* the browser has stale Vaadin related things from the previous page.
*
*
* In other words we probably need a surgical way to scrub stale Vaadin things from users browser
* that only runs once, even if the script can be on the page multiple times. Alternatively we can
* just detect the problem and force a hard reload.
Expand All @@ -61,6 +61,13 @@ protected void doHeaders(RenderRequest request, RenderResponse response)
isPortlet3.set(true);
}

@Override
protected String getStaticResourcesPath() {
return getService().getDeploymentConfiguration().getStringProperty(
PortletConstants.PORTLET_PARAMETER_STATIC_RESOURCES_MAPPING,
"/vaadin-portlet-static/");
}

private boolean checkStaticResourcesConfiguration() {
return getStaticResourcesPath().startsWith("/o/");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.portlet.HeaderResponse;
import javax.portlet.PortalContext;
import javax.portlet.PortletConfig;
import javax.portlet.PortletContext;
import javax.portlet.PortletException;
import javax.portlet.PortletMode;
import javax.portlet.PortletRequest;
Expand Down Expand Up @@ -245,18 +246,25 @@ public void renderHeaders(HeaderRequest request, HeaderResponse response)

protected String getPortletScriptTag(RenderRequest request,
String filePath) {
// static bundle or context path?
// static bundle or context path?
// latter is more lenient for old projects, former is less friendly to caching
// current implementation uses portlet context to load the portlet
// methods JS file and Liferay implementation uses static bundle
String scriptSrc = getServerUrl(request) + getStaticResourcesPath()
+ filePath;
return "<script src=\"" + scriptSrc
+ "\" type=\"text/javascript\"></script>";
}

protected String getStaticResourcesPath() {
return getService().getDeploymentConfiguration().getStringProperty(
PortletConstants.PORTLET_PARAMETER_STATIC_RESOURCES_MAPPING,
"/vaadin-portlet-static/");
PortletContext portletContext = getPortletContext();
if (portletContext != null) {
String contextPath = portletContext.getContextPath();
if (contextPath != null && !contextPath.isEmpty()) {
return contextPath + "/";
}
}
return "/";
}

private static String getServerUrl(RenderRequest req) {
Expand Down Expand Up @@ -597,7 +605,7 @@ private Logger getLogger() {
* wants to be rendered in minimized state as well as other states, it
* should override this method and return true.
* </p>
*
*
* @return true is the portlet should be rendered in minimized state.
* Otherwise false.
*/
Expand Down

0 comments on commit 5a70934

Please sign in to comment.