Struts portlet projects share common characteristics with standard portlet and Struts projects, although there are some differences that you should be aware of. The Struts portlet project structure and related resources are dictated by the Struts Portlet Framework (SPF) support provided by WebSphere® Portal and included in the Rational® Software Development Platform.
Struts portlet projects are created using either the New Portlet Project or New Portlet Project (JSR 168) wizard. A default Struts-type portlet, and, optionally, 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.
Resource type | Files | Target directory | Notes |
---|---|---|---|
TLDs |
|
WEB-INF | |
JARs |
|
WEB-INF/lib | |
Configuration files |
|
WEB-INF | The <controller> element that defines the Request Processor class is automatically generated in the Struts configuration file. |
Deployment descriptors |
|
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:
Struts portlet tag library definitions appropriate for JSR 168 SPF and the list of Welcome-files supported for Struts modes are included in the web.xml file. |
The following sample configuration and deployment descriptor file snippets show representative tagging used within Struts portlet projects:
<controller processorClass="com.ibm.wps.portlets.struts.WpsRequestProcessor"> </controller>
<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>
<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 web.xml:
<taglib> <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri> <taglib-location>/WEB-INF/struts-html.tld</taglib-location> </taglib>
<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 portlet.xml:
<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>
The following sample configuration and deployment descriptor file snippets show representative tagging used within Struts portlet projects:
<controller processorClass="com.ibm.portal.struts.portlet.WpRequestProcessor"> </controller>
<taglib> <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri> <taglib-location>/WEB-INF/struts-html.tld</taglib-location> </taglib>
<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>