Creating Struts portlets and projects

 

+

Search Tips   |   Advanced Search

 

The Struts portlet project structure is dictated by the Struts Portlet Framework (SPF) support provided by WebSphere Portal and included in the Rational Software Delivery Platform.

You can create Struts portlet projects by using the New Portlet Project wizard. A default Struts-type portlet and a Web diagram file will be added in the process of creating the project. The wizard automatically generates Struts portlet configuration files and the necessary updates to the web.xml file, portal.xml file, and adds all of the SPF tag libraries and JAR files to the project, in the directory structure that is required.

The following types of resources that are defined by the Struts Portlet Framework are included in the project:

 

JARs

IBM API portlet

All the *.jar files with the exception of Blank.jar in the SPFLegacyBlank.war.

JSR 168 API portlet

All the *.jar files with the exception of Blank.jar in the SPFStandard.war.

 

Configuration files

Target Directory: WEB-INF

The <controller> element that defines the Request Processor class is automatically generated in the Struts configuration file.

 

Deployment descriptors

Target directory: WEB-INF

 

IBM API portlet

The following modifications are made to the standard web.xml file:

 

JSR 168 (standard) API portlet

The following items are included in the portlet.xml file:

 

IBM API portlet conventions

The following sample configuration and deployment descriptor file snippets show representative tagging used within Struts portlet projects:

struts-config.xml

The following controller section is added to all struts configuration files:

<controller processorClass="com.ibm.wps.portlets.struts.WpsRequestProcessor"> </controller>

web.xml

This shows a sample Struts portlet servlet that is added to the the web.xml file. (Struts portlet-specific values in bold.):

<servlet id="Struts_Unique_Servlet_Name">
     <servlet-name>Struts</servlet-name>
     <display-name>Struts Portlet</display-name>
     <servlet-class>com.ibm.wps.portlets.struts.WpsStrutsPortlet</servlet-class>

   <!-- Struts configuration -->
     <init-param>
       <param-name>config</param-name>
       <param-value>/WEB-INF/struts-config.xml</param-value>
     </init-param>
     <init-param>
       <param-name>struts-servlet-mapping</param-name>
       <param-value>*.do</param-value>
     </init-param>     

<!-- end of Struts configuration -->
</servlet>

The config parameter above is the standard way to define a Struts configuration file and modules. The struts-servlet-mapping parameter is the way for a Struts portlet to define what to use as a Struts action mapping, so that paths that should be treated as Struts actions can be recognized. This is used the same way as the "servlet-mapping" value when configuring an Apache Struts servlet. It is strongly recommended that extension mapping be used for the param-value.

The following is an example of servlet-mapping for a Struts portlet servlet. It is defined to refer to the Struts portlet, since this portlet is also a servlet.

<servlet-mapping id="Struts_Unique_ServletMapping">
      <servlet-name>Struts</servlet-name>
      <url-pattern>/Struts/*</url-pattern>
</servlet-mapping>

This is an example of additional tag libraries that can be added to the web.xml file:

<taglib>
    <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>

portlet.xml

This is an example of an abstract portlet defined in the portlet.xml file:

<portlet-app uid="A_Unique_ID:1" 
             major-version="1" 
             minor-version="0">

  <portlet-app-name>Struts Portlet Application</portlet-app-name>

  <portlet id="Portlet_1" 
           href="WEB-INF/web.xml#Struts_Unique_Servlet_Name" 
           major-version="1" minor-version="0">

    <portlet-name>Struts Portlet</portlet-name>

    <cache>
      <expires>0</expires>
      <shared>NO</shared>
    </cache>

    <allows>
      <maximized/>
      <minimized/>
    </allows>

    <supports>
       <markup name="html">
          <view/>
       </markup>
    </supports>

  </portlet>
</portlet-app>

This is an example of a concrete portlet defined in the portlet.xml file:

<concrete-portlet-app uid="A_Unique_ID:1.1">

  <portlet-app-name>Struts Blank Application</portlet-app-name>

  <concrete-portlet href="#Portlet_1">

    <portlet-name>Struts Portlet</portlet-name>
    <default-locale>en</default-locale>

    <language locale="en">
      <title>Struts Portlet</title>
      <title-short>Struts Portlet</title-short>
      <description>Struts Portlet</description>
      <keywords>WPS, Struts</keywords>
    </language>

    <config-param>
       <param-name>FilterChain</param-name>
       <param-value>StrutsTranscoding</param-value>
    </config-param>

    <!-- any additional Struts related config-param values added here -->

  </concrete-portlet>

</concrete-portlet-app>

 

JSR 168 (standard) API portlet conventions

The following sample configuration and deployment descriptor file snippets show representative tagging used within Struts portlet projects:

struts-config.xml

The following controller section is added to all Struts configuration files:

<controller processorClass="com.ibm.portal.struts.portlet.WpRequestProcessor">
</controller>

web.xml

This is an example of additional tag libraries to be added to the web.xml file:

<taglib>
    <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>

portlet.xml

This shows a sample Struts portlet added to the portlet.xml file:

<portlet>
     <portlet-name>StrutsPortletProject</portlet-name>
     <display-name>StrutsPortletProject portlet</display-name>
    <portlet-class>
        com.ibm.portal.struts.portlet.StrutsPortlet
    </portlet-class>

   <!-- Struts configuration -->
     <init-param>
       <param-name>config</param-name>
       <param-value>/WEB-INF/struts-config.xml</param-value>
     </init-param>
     <init-param>
       <param-name>struts-servlet-mapping</param-name>
       <param-value>*.do</param-value>
     </init-param>     <!-- end of Struts configuration -->

     <!-- Here is an example of edit mode initialization: -->
     <init-param>
       <param-name>config/html/edit</param-name>
       <param-value>/WEB-INF/struts-html-edit.xml</param-value>
     </init-param>

     <!-- The following snippets are generated by the portlet API. -->
     <expiration-cache>0</expiration-cache>
     <supports>
       <mime-type>text/html</mime-type>
       <portlet-mode>view</portlet-mode>
       <portlet-mode>edit</portlet-mode>
     </supports>
     <supported-locale>en</supported-locale>
     <resource-bundle> strutsportletjsr168.nl.StrutsPorltetJSR168PortletResource  </resource-bundle>
       <portlet-info>
           <title>StrutsPortletJSR168 portlet</title>
       </portlet-info>

   <portlet-preferences>  

     <!-- example of setting the first page of the html view mode -->       

     <preference>         
       <name>com.ibm.struts.portal.page.view.html</name>         
       <value>index.jsp</value>       
       </preference>  

     <!-- example of setting the first page of the html edit mode -->

       <preference>         

       <name>com.ibm.struts.portal.page.edit.html</name>
         <value>html/edit/index.jsp</value>
       </preference>

     </portlet-preferences>

</portlet>

Note: The config parameter above is the standard way to define a Struts configuration file and modules.

 

Related concepts

Generating Struts portlet actions and action mapping codes

Creating data access Web applications using Struts

Struts tools for application development

 

Related tasks

Creating Struts portlet projects

Creating portlets

Creating Struts portlet JSP files

Creating Struts applications

 

Related reference

Differences between Struts 1.1 and SPF tag library classes