• Home
  • RSS Feed
  • Log in

Inter Portlet Coordination with JSR 286
Posted by Vikas Gupta mid-afternoon: April 19th, 2009

Coordination between portlets is a very common requirement. An example of information sharing between portlets can be a weather portlet displaying the weather information of a city and a map portlet displaying the location of the city. Since, both the portlets would be using the same zip code for a user, there should be mechanism provided by the portlal containers to allow portlets to share the zip code.

Prior to JSR 286, the support for inter portlet communication was rather minimal and information sharing between different portlets was accompalished primarily using application scoped session objects or vendor specific APIs. Both of above methods were rather problematic as in the former maintaining the uniqueness of the session attribute over a complex aaplication was a concern and in the later portability of the portlet was hampered. In order to provide coordination between portlets the Java Portlet Specification v2.0 (JSR 286) introduces the following mechanisms:

  1. public render parameters in order to share render state between portlets.
  2. portlet events that a portlet can receive and send. 

Let's have a look how to use the above features.

Public Render Parameters

In JSR 168, the render parameters propagated by one portlet were only available in the render method of the same portlet. This is explained in the following figure.
 jsr-168-render

In JSR 286, the render parameters propagated by one portlet can be made available to the render methods of other portlets. This is explained in the following figure.
jsr-286-render

In order to allow coordination of render parameters with other portlets, within the same portlet application or across portlet applications, in JSR 286 portlets, the portlet can declare public render parameters in its deployment descriptor using the public-render-parameter element in the portlet application section. In the portlet section each portlet can specify the public render parameters it would like to share via the supported-public-render-parameter element. The supported public-ender-parameter element must reference the identifier of a public render parameter defined in the portlet application section in a public-render-parameter element. The portlet should use the defined public render parameter identifier in its code in order to access the public render parameter.

Let's see how it works..
Consider the following example..

1. Set the public render parameters at the portlet application level.

 
<public-render-parameter>
    <identifier>id1</identifier>
    <qname xmlns:x="http://sun.com/params">x:param1</qname>
</public-render-parameter>
<public-render-parameter>
    <identifier>id2</identifier>
    <qname xmlns:x="http://sun.com/params">x:param2</qname>
 </public-render-parameter>

2. Specify the render parameter the portlet would like to share in the portlet section.

 
<portlet>
<portlet-name>PortletA</portlet-name>
  <supported-public-render-parameter>id1</supported-public-render-parameter>
  <supported-public-render-parameter>id2</supported-public-render-parameter>
<portlet>
<portlet>
<portlet-name>PortletB</portlet-name>
  <supported-public-render-parameter>id1</supported-public-render-parameter>
</portlet>
<portlet>
<portlet-name>PortletC</portlet-name>
  <supported-public-render-parameter>id2</supported-public-render-parameter>
<portlet>

The public render paramters declared above are processed as explained in the figure below.
parameter-sending
Now, since the public render parameters are encoded in the URL, the values that can be shared between portlets are restricted to String and String arrays. Since, public render parameters are available only in the render method, the information shared by the portlets should be used for rendering the view rather than for processing the shared information. 

Portlet Events
Portlet events could be generated as a result of a user interaction with other portlets. The portlet event model is a loosely coupled, brokered model that allows creating portlets as stand-alone portlets that can be wired together with other portlets at runtime. Portlet programmers should therefore not make any specific assumptions about the environment of portlets they are running together with. The means of wiring different portlets together is portal implementation specific. An example where a portlet may want to offer receiving events is for state changes triggered by simple user interactions, e.g. adding an item to a shopping cart. By offering this as an event to other portlets these can trigger adding items to the shopping cart based on the user interactions happing inside these portlets.

EventPortlet Interface
In order to receive events the portlet must implement the EventPortlet interface in he javax.portlet package. The portlet container will call the processEvent method for each event targeted to the portlet with an EventRequest and EventResponse object.

Events are targeted by the portal / portlet container to a specific portlet window in the current client request. Events are a lifecycle operation that occurs before the rendering phase. The portlet may issue events via the setEvent method during the action processing which will be processed by the portlet container after the action processing has finished. As a result of issuing an event the portlet may optionally receive events from other portlets or container events. A portlet that is not target of a user action may optionally receive container events, e.g. a portlet mode changed event, or events from other portlets, e.g. an item was added to the shopping cart event. 

The JSR 286 event processing is explained in the following figure.
jsr-286-event-processing

To create portlets that use the eventing feature, follow these steps
1. Declare the events in the portlet.xml     
(i) Set the event definition at the portlet application level. This specifies the event name and the object type.

 
<portlet-app ...>
<portlet>
 . . .
 . . .
 </portlet>
 
 <event-definition>
   <qname xmlns:x="http:xebia.com/address">x:Address</qname>
   <value-type>com.xebia.Address</value-type>
 </event-definition>
</portlet-app>
  @XmlRootElement
  public class Address implements Serializable {
      public Address() {
      }
      private String street;
      private String city;
      private String country;
 
      //getters and setters
   }

Note: The object must be serializable and must be instrumented with valid JAXB annotation. This might be required to ensure that portlets can send events to and receive events from remote portlets. However, in case of local communication, portal containers, for optimization purposes, might not serialize event payload.

(ii) In the portlet section, specify the event name defined above for those portlets that want to publish this event.

 
<portlet>
  <description>ContinentPortlet</description>
<portlet-name>ContinentPortlet</portlet-name>
    .................
   <supported-publishing-event>
     <qname xmlns:x="http:xebia.com/address">x:Address</qname>
   </supported-publishing-event>
</portlet>

(iii) In the portlet section, specify the event name defined above for those portlets that want to process this event.

 
<portlet>
  <description>ContinentMapPortlet</description>
<portlet-name>ContinentMapPortlet</portlet-name>
  <supported-processing-event>
    <qname xmlns:x="http:xebia.com/address">x:Address</qname>
  </supported-processing-event>
</portlet>
<portlet>
  <description>ContinentInfoPortlet</description>
<portlet-name>ContinentInfoPortlet</portlet-name>
  <supported-processing-event>
    <qname xmlns:x="http:sun.com/events">x:Address</qname>
  </supported-processing-event>
</portlet>
 

2. Issue an event in the portlet that was specified as supported-publishing-event in the portlet.

public class ContinentPortlet extends GenericPortlet {
   public void processAction(ActionRequest request, ActionResponse response)
   throws PortletException,IOException {
	QName qname = new QName("http:xebia.com/address" , "Address");
        Address add = new Address();
        //set values in address
        response.setEvent(qname, add);
    }
}

3. Process the event in the portlet that has specified as supported-processing-event in the portlet

public class ContinentInfoPortlet extends GenericPortlet {
  public void processEvent(EventRequest request, EventResponse response) {
    Event event = request.getEvent();
    if(event.getName().equals("Address")){
      Address payload = (Address )event.getValue();
      //process payload here
    }
  }
}

Portlet events provide more sphisticated way of exchanging information between portlets as compared to public render paramters as they can be used to share objects rather than simple string values. They also provide an additional callback method, processEvent, which can be used to process the event information before the view for the portlet in rendered. Also, portlet events share the information in a type safe manner as the event payload id bound to a type which we declare in the portlet.xml. Also, portlet specification does not standardizes how to wire the portlets, so, portal containers are free to choose convenient mechanisms to wire the portlets together.

However, as per the portlet specification, portlet events are not as reliable means of communication as is JMS, since the specification does not mandate the portal containers to persist the portlet event data. So, in case of server failures, the portlet events can be lost.

Summary
In this blog, we discussed about the JSR 286 inter portlet communication features. First, we discussed about the public render parameters and how it works. Secondly, we discussed about the portlet events, and it's working. So, how to decide when to choose either of the above two portlets. I would use the following principle

In case, the receiver portlet, does not need to do any processing/businees logic, it is advisable to use public render parameters as they avoid the overhead for portlets event creation and wiring the portlets together, which is required in case of portlet events. As already discussed, wiring portlets together is portal container specific and is an addtional overhead. However, to allow receiver portlets to process the shared information and sending type safe values, we need to use portlet events. 

Overall, JSR 286 portlet coordination features make complex portal applications modular and manageable.

Note: The source code of for portlet events can be downloaded from here.

  • Share/Bookmark

Tags: JSR 286, portlets, websphere, websphere portal
Filed under websphere | 30 Comments »



30 Responses to “Inter Portlet Coordination with JSR 286”



    Web Space Server Developer Tools - Technology Says:
    Posted at: April 28, 2009 at 8:01 pm

    [...] Space Server and Liferay. Combining these with existing features like eventing (Vikas has done a nice writeup on this), you can do all of your Web Space Server development without leaving the comfort of your [...]



    WebSpace Server 開発ツール - Technology Says:
    Posted at: April 30, 2009 at 5:00 am

    [...] これらに加え、イベント (Vikas はこれについてよい記事を書いています) などの既存の機能も使い、 WebSpace Server での全ての開発を [...]



    Développez pour Web Space Server - Technology Says:
    Posted at: April 30, 2009 at 9:00 am

    [...] dans WebSpace Server et Liferay. Si l’on ajoute à cela les fonctions existantes, comme la gestion graphique des communications entre portlets (Eventing Storyboard), vous pouvez réaliser l’ensemble de vos développements Portal sans quitter votre [...]



    Neha Says:
    Posted at: June 29, 2009 at 7:58 am

    hi,
    Can you please send this sample project along with source code. I want to do co-ordination in jboss portal



    Vikas Gupta Says:
    Posted at: June 29, 2009 at 11:06 am

    Yes, I can.
    Can you please let me know where to send?



    Neha Says:
    Posted at: June 29, 2009 at 1:20 pm

    please send it to [removed to protect privacy]



    Mohammed Ali Says:
    Posted at: July 2, 2009 at 10:00 am

    Hi,
    Can I pass an arraylist or linked list of objects through the event. I mean instead of ” Address add = new Address();” we make ” LinkedList add = new LinkedList();
    Thanks You



    New 2 portlets Says:
    Posted at: July 2, 2009 at 10:55 am

    Hi,

    Neha can you send the sample for Jboss Portal after you finish, or publish it somewhere, so people interesed (like me) can download it ?

    I also have another question regarding JSR 286: can a portlet be reseted every time it is accesed (by this I mean to render it’s first page every time, not the portlet’s last state)? Can this be done using portlet events ?

    Regards



    Smitha Says:
    Posted at: July 3, 2009 at 4:38 am

    Hi Neha,

    I am started learning the portlets. Appreciate if you could mail the sample code for the portlet events to my email address: learner_jsp@yahoo.com

    Thanks,

    Smitha



    Naga Says:
    Posted at: July 10, 2009 at 3:00 am

    hi,
    Can you please send this sample project along with source code. I want to do co-ordination in websphere portal.

    Thanks,



    mrk Says:
    Posted at: July 13, 2009 at 3:03 pm

    Hi Vikas,
    Can you please send this sample project. I am working on interportlet communication on websphere portal.

    Thanks in advance..

    mrk



    Ambarish Says:
    Posted at: July 21, 2009 at 9:36 am

    Hi Vikas,
    I am new to the world of portlets. Your blog has been of great help to me.
    I am working on inter-portlet communication on WebSphere Portal Express. Can you pls send me the code to my email.

    Thanks in advance,
    – Ambarish



    Prabhu Ranagn Says:
    Posted at: August 7, 2009 at 11:50 am

    Hi Vikas,

    Can you please e-mail me the source code for developing IPC portlets. It would be nice if you can e-mail, the ‘Source code’ and ‘deployable *.sar or *.war’ file.

    Waiting for your early response….

    Regards,
    Prabhu.



    Inter Portlet Coordination with JSR 286 « Making difference with Technology Says:
    Posted at: September 9, 2009 at 4:34 pm

    [...] Inter Portlet Coordination with JSR 286 [...]



    Mani Says:
    Posted at: September 22, 2009 at 8:47 am

    I am new to portlets and trying to learn interportlet communication on websphere portal. It would be great if you could mail me the sorce code..
    thanks in advance..!!!



    Michael Haulussy Says:
    Posted at: September 25, 2009 at 12:23 pm

    I am investigating JSR-286 portals and I am very interested in IPC eventing, can you send me the sourcecode?

    Regads,
    Michael



    Bojan Says:
    Posted at: October 8, 2009 at 10:31 pm

    Hello,

    During a University project, one of the teams was in charge of the IPC configuration and they didn’t reached the goal.

    I’m trying, now that the project has finished, to do it myself because it looks like very interesting.

    Could you please send me the source of the project in order to help me in my quest? :)
    (kljakic.bojan@gmail.com)



    ravi Says:
    Posted at: October 13, 2009 at 7:01 pm

    Can send me source code to my email. Thanks in advance



    Nirmala Says:
    Posted at: October 15, 2009 at 3:22 pm

    Even after following all the above mentioned steps for Portlet Events, events are not getting triggered. Please let me know if any other configuration is missing in above explaination.



    Nirmala Says:
    Posted at: October 15, 2009 at 3:24 pm

    Also can you please send me the working version of source code of any example for IPC. Examples from net are not working!!



    Ved Swaminathan Says:
    Posted at: October 19, 2009 at 6:03 pm

    Could anyone send me the source code. PLease let me know if someone has got it.



    Beata Says:
    Posted at: October 21, 2009 at 1:11 pm

    Hi,
    Could anyone send me the source code too. My email: boobu@go2.pl

    Thanks!



    nirmal Says:
    Posted at: October 22, 2009 at 8:24 am

    Hi I am looking for source code so if any one has source code please do send to nirmal_p@rediffmail.com or please attach here so that every one can donwnload

    thanks in advance
    nirmal



    rita Says:
    Posted at: November 2, 2009 at 12:14 pm

    Hi,
    Can you also send me the source code, please!
    Thank in adavance,

    rita
    ritamalcata@hotmail.com



    digitalseance Says:
    Posted at: November 17, 2009 at 8:10 pm

    Nice writeup, I’m beginning my migration to IBM 6.1.x and beginning the migration to JSR286. We exploited the bug allowing multiple parameters being passed via JSR168 wires and now have to migrate to passing complex types via events. After reading your blog, and a little on the info center, I migrated our first app in under 20mins. Thanks! ::digg::



    Navs Says:
    Posted at: November 20, 2009 at 4:54 pm

    Hi Vikas,

    It is indeed the first writeup that is well written and is not promoting any brands!!
    Could you please email me the source code @ the email address I have provided in this “Leave a Reply” form.

    Cheers,
    Navs.



    Rohit Says:
    Posted at: November 22, 2009 at 8:15 pm

    Its very gud to understand jsr286 difference with 168. It is described in a well mannerd with diagrams n all. Thanks buddy!!



    Sharad Says:
    Posted at: November 23, 2009 at 11:21 am

    Hi Vikas,

    Can you pls. send me the source code at tosharad@gmail.com

    Thanks a lot!!



    Raghav Says:
    Posted at: January 5, 2010 at 8:22 pm

    Can you pls. send me the source code at raghscool@gmail.com



    IPC ou communication inter portlet 2. JSR286 « natoine Says:
    Posted at: January 22, 2010 at 3:04 pm

    [...] compatible avec une vision composant. Pour ceux qui veulent en savoir plus, la ressource issue du blog xebia est la meilleure référence que j’ai trouvé. Dans cette ressource, vous retrouverez [...]



Leave a Reply

Click here to cancel reply.

Deployment automation for Java application running on Websphere, WebLogic and JBoss

Archives

  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009

Xebia Sites

  • Xebia Corporate
  • Xebia France
  • Xebia India

Categories

  • Java (279)
  • Agile (109)
  • General (50)
  • Testing (42)
  • Performance (42)
  • Hibernate (36)
  • Scrum (33)
  • Podcast (31)
  • Architecture (31)
  • Spring (28)
  • SOA (24)
  • Maven (22)
  • Project Management (22)
  • Flex (17)
  • JPA (17)
    • JPA implementation patterns (13)
  • Eclipse (15)
  • Quality Assurance (14)
  • Middleware (19)
  • Frameworks (13)

Tag Cloud

    XML Semantic Web Scala Xebia product owner Maven Testing Architecture Seam Poppendieck Java fitnesse Scrum Closures JavaOne Groovy SOA Introduction to Agile Agile Awareness Workshop IntelliJ Performance Spring Hibernate Functional Programming Lean qcon esb Ajax Agile Grails
medicin depression buy phentermine without a perscription aricept generic hair loss help how do you prevent bone loss urinary tract infection symptoms viagra sex domination cialis viagra cures for throat infection buy sumycin acne care new medication for cancer treatment help for sleeping problems on-line pharmacies cure snoring medications to help clot blood what is aspirin buy zestoretic bronchitis vs pneumonia back pain muscle acne face medication muscle women pain behind knee fat blocker man health arthritis natural cure woman health women insomnia cheap phentermine online cats and irritable bowel syndrome buy cialis generic online nutritional diet for osteoporosis abnormal blood clots treatments for hair loss what is zyprexa dental whitening products impotence herbs drugs for diabetes allergy prevention buy canada levitra Mentax adhd in children hair loss in woman medicines for blood clot online imitrex viagra buy free dog products clindamycin drug how to stop hair loss chloramphenicol discount drug viagra what valium does permanent hair loss heart failure medicine avapro 150mg ordering viagra online food allergies order viagra online online viagra prescription carisoprodol mg improve your skin discount erectile dysfunction medication buy xanax online buy order viagra scabies teatments information allegra vitamine b1 diazepam breast cancer support free stop smoking cipro side effects ultram cheapest treatment attention deficit disorder discount vitamins supplements how to get viagra online synthroid buy cheapest cialis zyrtec online how to clear acne preventive osteoporosis immune stimulants what is hoodia On Line Viagra getting over the pain diflucan dosage health asthma online stores hair loss products blood clot drugs colon parasites hair loss products discount medicine pravastatin buy griseofulvin tablets order indomethacin dog health products how to take a beta-blocker diazapan is valium treating cold sores chronic pain drug what is osteoporosis stress drug tooth whitening lowering cholesterol naturally legality of buying cialis online order levitra treatment for insomnia cheapest cialis index depakote overdose alprazolam condom sales treatment of yeast infection xanax sales taking viagra after cialis how to control pain new birth control chest pain health prozac prescription blood clots viagra in mexico chlamydia pill cancer drugs cold flu drugs how do i order viagra online super viagra acyclovir medicine benadryl dosage erythromycin pregnancy buy contoured condom chronic muscle pain pet health dogs treatment attention deficit disorder dental teeth whitening asthma medicine free prescription drugs herpes drug diabetes treatment buy tooth whitening gel cheap fast valium generic levitra buy cheapest viagra online lopressor drug pharmacy drug prices ultram dosing treatments for bipolar disorder neurontin withdrawal parasite medication chlamydia tips for increasing breast size ways to enhance breast what is valium used for metformin tablet order birth control hair loss for men how does xanax work treatment hepatitis c rythmol cheap acai antioxidants nexium generic blood pressure pills levitra online no prescription Levitra Online medications on line motion sickness drugs bactrim online order roxithromycin nicotine where can i order viagra immune supplements buy erexin v bph prostate allopurinol xanax for depression drug new smoking stop cheap impotence drug generic cialis delivery new treatment for depression antibiotics for cat viagra china alternative medicine cholesterol viagra dose anxiety disorder treatment severe muscle pain treatment of cancer calcium carbonate penis enlargement without pill valium maximum dosage reasons for high blood pressure energy product breast enlargement info cheap effexor building your body wrinkle cream aricept dosage alpha blocker increasing female sex drive valium depression new pain meds no rx xanax drug trileptal mg imitrex avapro 150mg medicine drugs contraception female claritin pill medication for acne med orders buy viagra internet levitra effect treatment for blood clots order sominex buy creatine buy precose cheap viagra overnight lopressor drug body building info health drugs general health and medical what is diazepam eye infections in dogs online prescription pills diclofenac tablet new medication anxiety buy citalopram medication male enhancement enhancement fat blocker medicine for throat infection order cardizem about soma health remedies for dogs generic xanax cheap zyrtec for depression medicine viagra sex domination buy acne skin care product hypnosis help study cure vaginal yeast infection weight loss supplement program muscle pain in leg how to increase erection buy viagra what is cla augmentin doses gaining muscle mass health med online heart rate treatments lopressor drug dog ear canal phentermine without prescription viagra order online weight loss glipizide diabetes astelin generic fat blocker buy gel tooth whitening cheap wellbutrin online weight loss program buy antiox anti-biotics acne skin treatmen tramadole vpxl pill drugs affecting levitra immune system support augmentin hypothyroidism medication buy erexin v uy prescription medication without a prescription buy discount order osteo arthritis online buy pilocarpine cheapest place to buy phentermine parasite treatment impotence help body fat loss viagra herb alternative constipation supplements treatment dementia adhd and medications muscle spasm relief viagra online cheap relieve upper back pain stop hair loss discount viagra online menstrual cycle problems antifungal shampoo side effects ativan gabapentin medication where can i buy viagra diazepam buy soma online clonidine dosage viagra gel top hair loss fast antibiotics cure chlamydia skin fungal infections drug zofran give up smoking alternative medicine cholesterol sleeping help best online viagra scams prednisone 10mg viagra sex domination lotensin easy weight loss pain meds without prescription over the counter drugs new high blood pressure medic generic compazine cetirizine drug order phentermine best fat blockers woman enhancement supplement drug zofran buy precose new drug treatment for cancer how to increase fertility viagra in australia benadryl dosing buy alcoholism medications order l arginine buy diazepam generic for ativan ativan prescription drugs weight loss treatment for chest pain woman health where can i buy phentermine online skin fungal infection give up smoking viagra on line hoodia information how does osteoporosis occur buy viagra online buy alcoholism medications depakote overdose klonopin pill tetracycline capsules what is high blood pressure bladder control for dogs generic for lipitor glucophage online pharmacy gabapentin dosage treating yeast infections dog health info cymbalta anxiety cheap tramadol without prescription hydrea drugs used for cancer cure for high blood pressure alcohol and valium relief from constipation liver infection treatment cialis soft zantac medication help sleep problems all natural antibiotics order medication without prescription sleep problems free hypnotherapy gaining muscle mass cheap viagra order online natural help for pain how to buy viagra drug price celebrex information otc diuretic levitra 10 mg buy medicine online pets products relief foot pain cialis without prescription med care cheapest generic cialis rapid hair loss pain medications generic side effects meds without prescriptions cat anxiety buy simplicef natural cure arthritis effects of high blood pressure lowest price generic viagra how to get birth control new breast cancer drug buy topamax blood pressure meds when are beta blockers prescribed how to get pain meds order fosamax online viagra name order viagra viagra cialis cat's eye health how to relieve lower back pain treating ear infections diazapan is valium online pain doctors high blood pressure in elderly medication to stop smoking wellbutrin dosages diabetes blood sugar levels weight loss diet pill side effects of prescribed pain pills drug list high blood pressure buy cialis online in usa ultram cost how to help osteoporosis how to use clomid discount brand viagra wellbutrin cymbalta buy pills without a prescription buy pain medicine online tab tramadol depression symptoms treatment how levitra work hypertension medications beta blockers prevent premature ejaculation xanax interactions with other medicines purchase medicine on line does alli work xenical mexico prescriptions buy sumycin uy prescription medication without a prescription ambien cost methocarbamol effects cheap beta blockers cats bladder reduce cholesterol naturally metformin tablet scabies medicine breast enhancer pills body building over 50 order viagra cheap zestril medication how to buy prescription medications online pharma kamagra drugs depression ear infection symptoms big muscle controlling blood pressure pain meds and pregnancy buy diazepam without prescription skin allergies antibiotic zoloft buy weight loss nutrition program Buy Cialis breast increase meds without prescriptions blood clots medical edema treatment for flu best hangover remedy diabetes drugs