Add custom JS libraries in JPP 6 to be used by all portlets

Solution Verified - Updated -

Environment

  • Red Hat JBoss Portal (JPP)
    • 6.x

Issue

  • How to add some custom JS libraries inside my Jboss Portal so that all my portlets would just access it ?

Resolution

Below steps should be followed in order to load custom JS files at the portal level and use it in a portlet.

1) Inside portal.war (or in a portal extension's war), created a folder called js which holds the script files.

/opt/JBoss/JPP_6.2_ER5/jboss-portal-6.2.0.ER5/jboss-portal-6.2/gatein/gatein.ear/portal.war/js/hello.js

2) The hello.js is a simple script file and has following in it :

function helloWorld()
{alert("js loaded at portal level")}

3) In the /portal.war/WEB-INF/gatein-resources.xml (or in the portal extension's war), loaded the js file/s (which should be loaded at the portal level) as below :

<gatein-resources>
...
...
<scripts>
    <name>helloNew</name>
    <script>
      <path>/js/hello.js</path>
    </script>
  </scripts>
</gatein-resources>

4) Now, in the portlet's gatein-resources.xml , use the loaded javascript as :

<gatein-resources>
<portlet>
    <name>SimplestHelloWorldPortletNew</name>
...
<scripts>
      <depends>
        <scripts>helloNew</scripts>
      </depends>
    </scripts>
  </portlet>
</gatein-resources>

5) On adding the portlet to a page and accessing it, it shows a pop up which signifies that script has been loaded.

If you want to load or change the default JQuery version that ships with EPP, refer https://access.redhat.com/solutions/428223

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments