Saturday, 1 November 2014

Portlet Development Beginners Concept Building

Portlet Development Beginners Concept Building



To start development of portlets, let us inspect how things work. 

When an user lands on a portal page, the portlets in that page shows their content after going through render methods like doView(). 
Suppose there is a form present in a portlet and the user puts some data and submits the form. Then that portlet goes through a two phase lifecycle.
First the processAction() method is executed and then the render method like doView() gets executed.

In the processAction() method, we typically do POST actions, in the sense that we retrieve form data, do some processing, connect to a database and fetch data and perform other business logics. 

In the render methods (doView, doHelp, doEdit) we typically do GET actions like getting different objects from the application/session etc and setting the data in request/session as per requirement of the corresponding jsp page that is to be displayed to the user. 

Also the communication between the processAction() method and the render methods of the portlet is achieved through the setRenderParam methods of the ActionResponse object in the processAction method.

public void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException {
String userData = request.getParameter("formParam");
response.setRenderParameter("userParam", userData);
}

The parameter set in the response object above are accessible in the doView() method as shown below:

public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
response.setContentType(request.getResponseContentType());
System.out.println("Printing from doView() method:"+request.getParameter("userParam"));
PortletRequestDispatcher requestDispatcher = getPortletContext().getRequestDispatcher(getJspFilePath(request, "myHomeView.jsp));
requestDispatcher.include(request,response);
}


In jsp, we can get some implicit portlet objects like portletConfig, portletSession, renderResponse, renderRequest etc. But to make these implicit objects  available we need to write the following tag in the jsp:
<portlet:defineObjects/>

portletConfig is an object of the type PortletConfig
portletSession is an object of the type PortletSession
renderRequest is an object of the type RenderRequest
renderResponse is an object of the type RenderResponse

In this fashion, any parameter set in the processAction() method can be accessible from the jsp as shown below:
<% renderRequest.getParameter(“userParam”); %>


Wednesday, 1 October 2014

Portlet Development Beginners Tasks

 Portlet Development Beginners Tasks


These are the assignments which you may follow to pick up portal skills. It will definitely help you in building portlet application development skill. 
 

  1. Hello World Portlet :
    Create a form in the view mode.
    Submit the form. Retrieve the values.
    Display the submitted values again in the view mode.

  2. Set up a connection pool and datasource in the application server and use the datasource in a portlet to obtain a connection. Fetch some sample data to show in the portlet.

  3. Create an URL in the view jsp, which when clicked, the user will be able to go to the edit mode.

  4. Put a single choice dropdown and a submit button in the jsp page. Populate the dropdown with values: view, edit and help. When the submit button is clicked, the portlet mode will be decided on the selected value in the dropdown.

  5. Create a Weather Portlet that will display some city names like Kolkata, Delhi, Mumbai, Chennai etc and their corresponding maximum and minimum temperature values reading from an XML file.

  6. Introduce portlet preferences in the Weather Portlet. The user can go to the edit mode of the portlet and choose which cities they want/don't want to see in the view mode.

  7. Create two portlets in your application. Use PortletSession for inter-portlet communication to pass an object from one  portlet to another portlet deployed in the same page.

  8. Use co-operative portlets for inter-portlet communication to pass a String from one  portlet to another portlet deployed in the same page.

  9. Use co-operative portlets for inter-portlet communication to pass a java object from one  portlet to another portlet deployed in the same page.

  10. Use portlet events for inter-portlet communication to pass a java object from one  portlet to another portlet deployed in the same page.

  11. Do Communication between a servlet and a portlet like passing a parameter between a portlet and a servlet.