Hello World Portlet

We are going to create a portlet using the Eclipse Java perspective. Go to the express-demo project, click on the com.bluesunrise.portal.portlets.tutorial package, and create a new Java class:

You will see a new portlet in Eclipse named BonjourWorld. Go ahead Override and Implement the following methods:

Each one of these methods is associated with a portlet mode. Lets make these methods actually do something. Since we are in the render phase when doView/doEdit/doHelp are called, its probably best to render something. The RenderResponse renders content to the output stream of the portlet. Set the content type on the response, and then print a hello world message using a Java Writer:

	
	 
    protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException
    {
        response.setContentType("text/html"); 
        response.getWriter().println("<b>Bonjour: View Mode</b>");
    }
	     
	

Repeat the same process for Edit and Help modes. Now lets edit the portlet.xml, and create a portlet descriptor entry for our portlet. Notice that the <supports> element contains that same portlet modes that we support in our do methods.

	
	 
    <portlet>
        <description>Bonjour Monde Portlet</description>		
        <portlet-name>BonjourMonde</portlet-name>	
        <display-name>Bonjour Monde</display-name>
        <portlet-class>com.bluesunrise.portal.portlets.tutorial.BonjourWorld</portlet-class>	        
        <supports>
            <mime-type>text/html</mime-type>
            <portlet-mode>VIEW</portlet-mode>
            <portlet-mode>EDIT</portlet-mode>
            <portlet-mode>HELP</portlet-mode>            
        </supports>
        <supported-locale>en</supported-locale>      	
	    <portlet-info>
        <title>Bonjour Monde</title>
          <short-title>Bonjour</short-title>
          <keywords>tutorial,bonjour,hello</keywords>
       </portlet-info>
	</portlet>	 
	     
	

Previous Next