Knowledge Base (Display) Knowledge Base (Display)

Inter-portlet communication

Inter-portlet communication

This article describes how to get started with the communication between reportlet windows and your own portlets, and  is mainly intended to Java developpers.   

1-Overview

2-How to develop a parameters portlet?

3-How to send events from your custom portlets to the reportlet windows?

4-Events qualified name

5-Sending an event through "processAction"

6-Receiving an event from the reportlet

 

Overview

Visioneo reportlet can exchange informations with other portlets on the same page. It is particularly useful if you want to make use of your own report parameters widgets. Have a look at the storelet demo to see how reports can interact with other components. Possible actions are:

  • Send new parameters values to a reportlet. As you will see in this article it is pretty easy to design a custom parameter portlet, such the one implemented in the professional edition.
  • Send which report to display to a reportlet (allows to implement your own report browser),
  • Receive informations from the reportlet (current displayed report and its parameter values)

 

How to develop a parameters portlet?

We can find many tutorials on the web showing how to develop a simple portlet. Unless you need a cross-portal one,  the best option is to refer to the targetted portal documentation. By developing a component specifically for a portal, we can take advantage of portal resources such user interface features, and get a more valuable help from portal forums. Although it is based on a standard, developing a cross-portal portlet might be much more challenging.

Every major IDE such Eclipse & Netbeans have plugins to speed up your portlet creation. If you already have a knowledge of Java, you should quickly be able to deploy a "Hello World" portlet, and little by little adding your parameters widgets in your "view mode" such datepickers, combobox static or based on a database, etc. To implement these widgets, we have various choices:

  • Using the javascript framework embedded in your portal (yui / AlloyUI on Liferay 6, webui on gatein, jquery on uPortal & Liferay 5, etc.). This shoud be your favorite choice.
  • Embedding your own javascript framework, as the reportlet does with jQuery.
  • Using a java framework  such GWT.

How to send events from your custom portlets to the reportlet windows?

Once your parameters widgets are ready in a custom portlet, we have to send selected values to reportlet windows and trigger a report refresh.

In the JSR 286 standard, there are 2 ways to exchange informations between portlets:

  1. Public shared parameters
  2. Portlets events

Visioneo reportlet makes use of events. If you plan to implement your own parameters portlet , first if it is not yet done you need to understand a concrete example implementing these portlet events. To achieve that,  this article by Javaworld is a very good start.

Shortly, here are the main steps:

  • declare an event in your portlet descriptor,
  • Send a portlet action when a user has selected new values. For example in a JSP page, use the portlet action tag in a form submit.
  • In your portlet action handler ("processAction" method):
    • Build a query string (your parameters values with a '&' separator)
    • Trigger an event with this query string

That's all! Not so easy, but not that much difficult neither! An example of the processAction method is provided later in this article.

Note another option smooth, simple and efficient is described in the 'Ajax inter-portlet communication' article (Professional Edition). Please refer to this article, you can easily adjust your custom portlet to make it work both with the standard events described in this article, and ajax events.

Events qualified name

Your portlet must declare the events qualified name in its portlet.xml file:

  • Sending an event to the reportlet: 

<qname xmlns:x="org.visioneo.portlet.synchro">x:visioneoSynchro</qname>

  • Receiving an event from the reportlet:    

<qname xmlns:x="org.visioneo.portlet.reportinfo">x:visioneoReportinfo</qname>

  • Declare in your portlet.xml, in the portlet section:     
      <supported-publishing-event>
           <qname xmlns:x="org.visioneo.portlet.synchro">x:visioneoSynchro</qname>
      </supported-publishing-event>

 

      <supported-processing-event>  
           <qname xmlns:x="org.visioneo.portlet.reportinfo">x:visioneoReportinfo</qname> 
      </supported-processing-event>         
              
 
And in the portlet app section (after your portlets definitions in portlet.xml) :
 
    <event-definition>
        <qname xmlns:x="org.visioneo.portlet.reportinfo">x:visioneoReportinfo</qname>
        <value-type>java.lang.String</value-type>
    </event-definition>    
 
     <event-definition>
        <qname xmlns:x="org.visioneo.portlet.synchro">x:visioneoSynchro</qname>
        <value-type>java.lang.String</value-type>
    </event-definition>
 

Sending an event through "processAction"

When an action is triggered from a portlet JSP page, your portal will automatically look for a "processAction" method in your portlet and invoke it. With the qualified name defined above, here is a sample java code which allows to send an event to the reportlet window(s):

@Override
    public void processAction(ActionRequest request, ActionResponse response) throws PortletException,IOException {
// an action has been fired from your JSP page! we must build an event message
// and send it to reportlets windows (you should encodeURL parameters values if necessary)
 
String year = (String) request.getParameter("year");
String view = (String) request.getParameter("view");
String theme = (String) request.getParameter("theme"); 
String eventMessage= "Year="+year+"&View="+view+"&Theme="+theme;
 
QName EventQNamePublish = new QName("org.visioneo.portlet.synchro", "visioneoSynchro"); 
 
response.setEvent(EventQNamePublish, eventMessage);
}
 
  • Sending the report parameters only:

year=2011&office=paris&products=PR02345,PR984343   

In this example, 3 parameters are sent to the reportlet(s) windows present on your page. The 'products' parameters is multi-value. Each reportlet window receiving this event is able to detect which parameters are consistent. For example, if the report set up in a reportlet window does not contain 'office' parameter, it ignores it and only applys 'year' and 'products'. These new parameters are then persistent for further requests, exactly like if they were selected with toolbar parameters dialog.

  • Sending the report only:

__report=visio-chart-radar

The engine will look for the visio-chart-radar.rptdesign file in your reports hierarchy, and display it in the reportlet window with default report parameters. The new report is then persistent for further requests, exactly like if it was selected with the toolbar ajax report browser. Not you don't have to specify in which subfolder this report is, the reportlet engine will take care of this for you.

Please not that sending the __report parameter through an event only makes sense if there is only one reportlet window on your page.
  • Sending both parameters and report:

__report=visio-chart-radar&year=2011&office=paris&products=PR02345,PR984343

The engine will look for the visio-chart-radar.rptdesign file in your reports hierarchy, and display it in your reportlet window with query parameters received. This new report and its parameters are then persistent for further requests

Receiving an event from the reportlet

With the qualified name defined above, you can process the event sent by the reportlet:

    @ProcessEvent(qname=visioneoReportinfo)
    @Override
    public void processEvent(EventRequest request, EventResponse response) {
        // a synchronzation event has been fired from the reportlet
       String event=request.getEvent().getValue().toString();   
       //do some stuff...
    }//end method event

 

These kind of events can be triggered with the toolbar extended feature. See the jsp page <reportlet root>/WEB-INF/jsp/visioneoPortlet_toolbar-ext.jsp for a concrete example.

Tags: architecture developers
Average (0 Votes)
Most Recent
Toolbar portlet 01 April 2015