3.5 Developing portlet applications

 <  Day Day Up  >  

The wizard will create a sample skeleton you can use as a foundation for your portlet development. Figure 3-10 on page 137 shows the result of creating a basic portlet application with the wizard.

Figure 3-10. Folder structure and contents of a basic portlet application

graphics/03fig10.gif

3.5.1 Portlet application contents

The generated project contains the following folders and files by default:

  • Java Source : this folder contains the Java files that make up the portlet application. By default, the wizard assumes you will create a basic portlet following an MVC approach and creates a simple Java bean for you. Whatever package name was specified in the fourth screen of the wizard will be created. If a simple class name was specified without a package, the wizard will place the portlet in a package named portlet.

  • Web Content : this folder contains everything needed to deploy the application to the portal. Essentially, this folder will become the.war file. This folder contains three sub folders:

  • Package / jsp : this folder will contain all the JSPs used by the application to create the content of the portlet. For each markup you choose to support, a directory will be created containing JSPs for each mode a portlet may support.

  • META-INF : this folder contains the MANIFEST.MF file.

  • WEB-INF : this folder contains the compiled code and deployment descriptors used by the Portal to install the application.

    - classes : if your compiled portlet class files are not packaged into a jar file, they are included in this directory. The complete package structure is created in this folder.

    - lib : this directory contains any jar files that your application makes use of and which are not normally available in the portal environment via the classpath. Also, if you have packaged your compiled portlets into a jar, the jar file is placed in this directory.

    - tld : this is included to allow JSPs to compile and recognize the custom tags available in the portal environment. This folder and file are not required at deployment time since the tld is installed with Portal. To make maintenance easier and more reliable, you may choose to delete this file upon deployment.

    - ibm-web-bnd.xmi : this file is not used by the portal environment but is included with all Web applications created in WebSphere Studio.

    - ibm-web-ext.xmi : this file is not used by the portal environment but is included with all Web applications created in WebSphere Studio.

    - portlet.xml : this is the deployment descriptor required by the Portal server to install the portlet application. It must be located under the WEB-INF folder or installation will fail.

    - web.xml : this deployment descriptor is required by the application server to install the Web application. It must be located under the WEB-INF folder or installation will fail.

  • images : this folder is not created for you by the wizard. However, if the JSPs you create use images, it is a good practice to place them in an images folder under the Web Content directory and access them as demonstrated in Example 3-1.

Example 3-1. Accessing images in JSPs
 <IMG src='<%=response.encodeurl(/books/4/455/1/html/2/images/database.gif)%>' /> 

3.5.2 Generated classes

Selecting Basic portlet in the wizard will generate some classes for you, depending on the number of modes your portlet supports.

  • Portlet : this is a simple portlet extending from PortletAdapter and implementing the four modes a portlet may support. Each method is very similar to the code in Example 3-2. Of course, each do method (doView, doEdit, doHelp, doConfigure) will need to call (include) the appropriate JSP.

    Example 3-2. Sample doView method
     public void doView(PortletRequest request, PortletResponse response) throws PortletException, IOException {    // Make a View mode bean    FirstPortletViewBean viewBean = new FirstPortletViewBean();    request.setAttribute(View_BEAN, viewBean);    // Save name in the View mode bean    viewBean.setPortletName("FirstPortlet"); // Invoke the JSP to render getPortletConfig().getContext().include(View_JSP + getJspExtension(request), request, response);    } 
  • PortletSessionBean : this simple JavaBean stores portlet instance data in a portlet session. Example 3-3 demonstrates the code in the bean.

    Example 3-3. Sample PortletSessionBean
     public class FirstPortletPortletSessionBean {    private String formText = "";    public void  setFormText  (String formText) {         this.formText = formText;     }    public String  getFormText  () {         return this.formText;     } } 
  • PortletViewBean: this simple JavaBean passes data from the portlet to a JSP for markup rendering in View mode. If you have defined that your portlet will support more modes then it will create PortletEditBean, PortletConfigBean and PortletHelpBean to render their respective modes. Figure 3-4 on page 140 demonstrates the code in the bean.

    Example 3-4. Sample PortletViewBean
     public class FirstPortletPortletViewBean {     private String formActionURI = null;    public void setFormActionURI(String formActionURI) {         this.formActionURI = formActionURI;     }    public String getFormActionURI() {         return this.formActionURI;     } } 
  • PortletView.jsp : several JSPs are created for you by the wizard. They are simple in functionality. They retrieve their respective bean from the request object and print out the name property. Example 3-5 displays the code. Initially, all JSPs have the same functionality, but different text.

Example 3-5. JSP code
 <%@ page contentType="text/html" import="java.util.*, firstportlet.*"%> <%@ taglib uri="/WEB-INF/tld/portlet.tld" prefix="portletAPI" %> <portletAPI:init/> <DIV style="margin: 6px"> <H3 style="margin-bottom: 3px">Welcome!</H3> This is a sample <B>view mode</B> page. You have to edit this page to customize it for your own use.<BR> The source file for this page is "/Web Content/firstportlet/jsp/html/FirstPortletPortletView.jsp". </DIV> 
 <  Day Day Up  >  


IBM WebSphere Portal V5 A Guide for Portlet Application Development
IBM Websphere Portal V5: A Guide for Portlet Application Development
ISBN: 0738498513
EAN: 2147483647
Year: 2004
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net