0

I need to add some behavior to all my portlets.
It must be some ajax query that check some condition and if it is true - show message.
At the first I decided to add some html to my portal skin for my applications. In this html I add js-script to make ajax query. But I don't know the context, to send query, because we use WSRP to access our portlets. Thats why I cannot get WSRP context and make query.
Second thought was to add common jsp in all portlets, and in this jsp make logic (from jsp I can get context). But it is not good if I will change all portlets jsp (using tag "include").
So my questions next:

  1. How to add behavior to all portlets?
  2. How to get WSRP context in JS?
  3. How to add jsp to all portlets, without changing portlets jsp?

P.S. And I cannot touch portal's theme, anyway.

zildarius
  • 3
  • 3
  • I've never tried to use WSRP, but I have common understanding what it is. What do you mean under WSRP context? What about portal theme? It is not an option? – Georgy Gobozov Jan 16 '15 at 10:21

1 Answers1

1

You should be able to use a global portlet filter for this in WebSphere Portal. You create a WAR module with the filter class in it, and deploy it to the application server on which WPS is running. It must have a file called plugin.xml in WEB-INF which describes your global filter(s) via eclipse plug point mechanisms within Portal. Your class must implement any of the sub-types of javax.portlet.filter.PortletFilter standard interfaces, meaning the code you write is standards based.

If you implement a global portlet filter, you must understand that it will be invoked for every portlet invoked on the portal - including administrative ones. To avoid running your intended logic where you do not wish to do so, check the context path of each request.

From the WPS Knowledge Center article:

Because global portlet filters affect all portlets running in the given portlet container, the console modules that are contained in the Integrated Solutions Console are also filtered. It is important to test your filter implementation for undesired side effects on console modules or portlets. One approach is to test by checking the context path of the request in your filter logic.

I don't know the context path of the WSRP portlet off top of my head, but some SystemOut logging should help you identify what this value is and point you in the right direction.

Lastly, there is an article with sample code describing the technique on the portal wiki.

Scott Heaberlin
  • 3,364
  • 1
  • 23
  • 22
  • No problem. Please be sure to mark as answered if this solved your issue. – Scott Heaberlin Jan 16 '15 at 15:31
  • I must answer. Really, it is works. I asked question half year ago, but need it only now. So - it is works, as I want. I made filter, and so added additional html-part, at the page begining. `@Override public void doFilter(RenderRequest request, RenderResponse response, FilterChain chain) throws IOException, PortletException { try{ String message = ""; PrintWriter out = response.getWriter(); out.print(message ); }catch(Exception exc){ exc.printStackTrace(); }finally{ chain.doFilter(request, response); }` – zildarius Aug 03 '15 at 10:04
  • I have one small additional question: may I use jsp, to output to response html, in filter? – zildarius Aug 03 '15 at 10:05