Changes to Struts JSPs
The JSPs for Struts applications must be modified to adapt to the way the portal server expects portlet URIs to be created. There are some changes to the tag library for HTML markup.
Creating portlet URIs
The Struts application paths, both to actions and to pages, must be sent and retrieved with portlet URIs. Portlet URIs have a specific format. A special API is used to generate the URI and add the required information to be passed to the portlet. If portlet URIs were not used, control would not get passed to the correct portlet. Thus, the portlet URIs get control passed to the correct portlet, with the additional path information needed by the Struts application made available. The Struts tags were modified to automatically provide this needed function.
Struts Action mappings are defined in terms of paths. The name and location of page objects (for example, JSPs) are also defined with paths. Thus, it is still necessary to associate the Struts path with an action sent to a portlet and to retrieve that Struts path when the portlet action is handled. The Struts URI is passed as a parameter so the Struts request processor can process the action. If the link is not an action, then the portlet processes the information and create the appropriate IViewCommand.
Typically a Struts application passes parameters on such a path with the query string on the HTTP URL. Often the actions that contain these paths are generated from tags that are provided by Struts. The most obvious examples are the tags for the HTML elements <link> and <form>. For IBM Struts portlets, the urlType attribute must be included in the <html:form>, <html:link>, and <html:rewrite> tags. These tags support the different types of URIs provided by the IBM Portlet API. This attribute can take the following values:
- return - Creates a portlet return URL indicating the caller of the portlet. For example, this URL can be useful for creating a form action that can take a user back to view mode from edit mode.
- standard - Creates a standard portlet URL.
- <html:form> (IBM portlets)
-
<html:form action="/logon" focus="username" urltype="return"> ... </html:form> - <html:form> (Standard portlets)
- <html:form action="/saveConfiguration.do" portletMode="view">
- <html:link> (IBM portlets)
-
<html:link page="/tour.do" urltype="standard"> <bean:message key="index.tour"/> </html:link>
Style sheets
Many existing Struts application use the rewrite tag to create a link element for a cascading style sheet. This is not the documented intention of the rewrite tag, which is supposed to create the same path as the link tag without the <a> element. Since the Struts Portlet Framework had to modify how links are created, the rewrite tag required some customizations to be used to create link elements for style sheets. The rewrite tag will create the same path as the link tag, except when the page or forward reference is to a CSS file. In the case where a CSS file is referenced, the rewrite tag will use the Jakarta Struts implementation, which results in a path to the CSS file. Here are examples of how to create link elements for style sheets using the Struts Portlet Framework.
- Using a forward
-
<link rel="stylesheet" type="text/css" href="<html:rewrite forward='baseStyle'/>"> - Using a page
-
<link rel="stylesheet" type="text/css" href="<html:rewrite page='/basestyle.css'/>"> - Using the portlet tags
-
<%@ taglib uri="/WEB-INF/tld/portlet.tld" prefix="api" %> <api:init /> <link rel="stylesheet" type="text/css" href="<%= portletResponse.encodeURL( basestyle.css ) %>">
Markup support
The Struts tag library support the additional markup languages that are supported by WebSphere® Portal. For HTML, the tags that create links support portlet URIs. Read Creating portlet URIs for details. Also, be aware of the restrictions for HTML output that is described in Markup guidelines.
There might be a case where the JSPs for a Struts application must run in both the servlet and portlet environment. For this reason, page level tags are implemented in tag libraries. The Struts application can use them in its JSPs, but the tags do not generate markup when run within WebSphere Portal.
You should also refrain from setting color, and fonts. The portal server supports skins and themes that give the page a consistent look and feel. The JSP should be authored so it adheres to the conventions of the theme by using the appropriate style sheet.