BlazeDS Contact Portlet

I wanted to learn how to i can use BlazeDS technology in portlet so i built a sample Contact Management application, This application has BlazeDSContactPortlet, which is used for returning a JSP that includes Flex from doView() method but once the Flex application is loaded it will directly communicate to MessageBrokerServlet inside the portlet, which is disadvantage of using BlazeDS in portlet application, you wont have portlet context in any other calls

You can download the sample code for this article from here

The BlazeDS application is nothing but a Servlet that you can add to your portlet application along with set of jars and you should be able to use it for communicating to Flex

  1. First download the blazeds.war and copy all the jars from its WEB-INF/lib to your WEB-INF/lib folder
  2. Then add HttpFlexSession listener and MessageBrokerServlet servlet to your web.xml like this


  3. The copy flex folder from the blazeds.war to your WEB-INF folder and change services-config.xml file so that value of my-amf channel points to the MessageBrokerServlet in your environment.

    <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
    <endpoint url="http://localhost:10040/wpcert/PA_BlazeDSContact/messagebroker/amf"

    The value of url will change based on your environment, in my case base URL of the server is http://localhost:10040 and the web application that has the MessageBrokerServlet is available at http://localhost:10040/wpcert/PA_BlazeDSContact, so i add /messagebroker/amf to it and that becomes value of my-amf channel url

  4. I am more interested in using BlazeDS to make calls to Java Objects in my portlet application from my Flex code, so first i declare the Java Class that should be invoked from my Flex class by adding this code to my remoting-config.xml file like this

    <destination id="contactdao">

    Now i can call methods of com.webspherenotes.flex.dao.ContactDAOImpl Java Class directly from my Flex code

  5. Now inside my flex code i can add this code to call methods of the ContactDAOImpl

    public var contactList:ArrayCollection;

    public var contactDAORO:RemoteObject;
    public function getContactList():void {
    contactDAORO = new RemoteObject();
    contactDAORO.destination = "contactdao";
    contactDAORO.endpoint ="http://localhost:10040/wpcert/PA_BlazeDSContact/messagebroker/amf"
    public function faultHandler (event:FaultEvent):void {, 'Error');
    private function getContactListHandler(event:ResultEvent):void{
    contactList = event.result as ArrayCollection;
    dgEmployees.dataProvider = contactList;

    <mx:DataGrid x="10" y="174" width="460" enabled="true" editable="false"
    <mx:DataGridColumn headerText="First Name" dataField="firstName"/>
    <mx:DataGridColumn headerText="Last Name" dataField="lastName"/>
    <mx:DataGridColumn headerText="Email" dataField="email"/>

    My Flex code has dgEmployees as DataGrid , that displays list of contacts in spread sheet format.

    I am calling getContactList(), flex method on the application load, this method is creating object of RemoteObject and pointing to URL where MessageBrokerServlet in my application is listening, then i am setting value of contactDAORO.destination to contactdao, when i do that MessageBrokerServlet, will take value of destination and find out the java class from that is mapped to contactdao by reading remoting-config.xml, in our case it is pointing to com.webspherenotes.flex.dao.ContactDAOImpl, then i am setting getContactListHandler, as flex method which should be used to handle result of this call and faultHandler method for handling error cases in this flex call.

    The contactDAORO.getContactList() means i want to call the getContactList() method of ContactDAOImpl class, this method returns ArrayList of Contact objects, on the flex side i am converting that ArrayList to ArrayCollection and i have a Contact flex class that is mapped to the Contact java class. Inside the getContactList() method i am setting the list returned by Java code as dataprovider for the datagrid

  6. This is how my Action Script Contact class looks like

    package com.webspherenotes.flex
    public class Contact
    private var _firstName:String;
    private var _lastName:String;
    private var _email:String;
    public function Contact()
    public function get email():String
    return _email;
    public function set email(value:String):void
    _email = value;
    public function get lastName():String
    return _lastName;
    public function set lastName(value:String):void
    _lastName = value;
    public function get firstName():String
    return _firstName;
    public function set firstName(value:String):void
    _firstName = value;


srjwebsolutions said...

We are leading responsive website designing and development company in Noida.
We are offering mobile friendly responsive website designing, website development, e-commerce website, seo service and sem services in Noida.

Responsive Website Designing Company in Noida
Website Designing Company in Noida
SEO Services in Noida
SMO Services in Noida

Vikas Chaudhary said...

Battery Mantra is Authorized exide car battery dealer in Noida and Greater Noida. We are providing our service in Indirapuram, Delhi, Ashok Nagar.

Exide Battery Dealer in Noida
Battery Dealer in Noida
Authorized Battery Dealer in Noida
Car Battery Dealer in Noida
Car Battery Dealer
Exide Battery Dealer

EG MEDI said... is online medical store pharmacy in laxmi nagar Delhi. You can Order prescription/OTC medicines online.
Cash on Delivery available. Free Home Delivery

Online Pharmacy in Delhi
Buy Online medicine in Delhi
Online Pharmacy in laxmi nagar
Buy Online medicine in laxmi nagar
Onine Medical Store in Delhi
Online Medical store in laxmi nagar
Online medicine store in delhi
online medicine store in laxmi nagar
Purchase Medicine Online
Online Pharmacy India
Online Medical Store