Skip to content

Commit

Permalink
feat: Delete Deprecated Usage of JS Tag Manager Definition in Generic…
Browse files Browse the repository at this point in the history
…DispatchedViewPortlet - Meeds-io/MIPs#175

This change will delete rendering of JSManager Tag when a single Portlet Application is requested to be displayed. This strategy isn't used anymore since the layout rendering is deferred and loaded using Ajax.
  • Loading branch information
boubaker committed Feb 6, 2025
1 parent dc48538 commit 5d67770
Showing 1 changed file with 7 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
import java.util.Map.Entry;
import java.util.Set;

import javax.portlet.*;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.PortletPreferences;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.apache.commons.lang3.StringUtils;
import org.gatein.portal.controller.resource.ResourceScope;

import org.exoplatform.portal.application.PortalRequestContext;
import org.exoplatform.portal.webui.application.UIPortlet;
import org.exoplatform.web.application.JavascriptManager;
import org.exoplatform.web.application.RequestContext;

/**
* This is a generic and simple Portlet class that dispatches the view to a
Expand All @@ -23,32 +25,10 @@ public class GenericDispatchedViewPortlet extends GenericPortlet {

private String viewDispatchedPath;

private String jsModule;

private String jsToAppend;

private boolean useJSManagerLoading;

@Override
public void init(PortletConfig config) throws PortletException {
super.init(config);
viewDispatchedPath = config.getInitParameter("portlet-view-dispatched-file-path");
String useJSManager = config.getInitParameter("use-js-manager");
if (StringUtils.isNotBlank(useJSManager)) {
useJSManagerLoading = Boolean.parseBoolean(useJSManager);
jsModule = config.getInitParameter("js-manager-jsModule");
if (StringUtils.isBlank(jsModule)) {
jsModule = ResourceScope.PORTLET + "/" + getPortletContext().getPortletContextName() + "/"
+ getPortletConfig().getPortletName();
}
jsToAppend = config.getInitParameter("js-manager-javascript-content");
if (StringUtils.isBlank(jsToAppend)) {
String alias = getPortletName();
jsToAppend = alias + " && " + alias + ".init && " + alias + ".init();";
} else if (!StringUtils.endsWith(jsToAppend.trim(), ";")) {
jsToAppend = jsToAppend + ";";
}
}
if (StringUtils.isBlank(viewDispatchedPath)) {
throw new IllegalStateException("Portlet init parameter 'portlet-view-dispatched-file-path' is mandatory");
}
Expand All @@ -66,11 +46,5 @@ protected void doView(RenderRequest request, RenderResponse response) throws Por
}
request.setAttribute("portletStorageId", UIPortlet.getCurrentUIPortlet().getStorageId());
prd.include(request, response);
if (useJSManagerLoading) {
PortalRequestContext portalRequestContext = (PortalRequestContext) RequestContext.getCurrentInstance();
JavascriptManager javascriptManager = portalRequestContext.getJavascriptManager();
String alias = getPortletName();
javascriptManager.require(jsModule, alias).addScripts(jsToAppend);
}
}
}

0 comments on commit 5d67770

Please sign in to comment.