Changes to Struts JSPs

The JSPs for Struts applications in the portal environment have to 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 and additional tag libraries have been added to support cHTML and WML markup.


Create portlet URIs

The Struts application paths, both to actions and to pages, must be sent and retrieved using 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 must be used to get control passed to the correct portlet, with the additional path information needed by the Struts application made available. The Struts tags have been modified to automatically provide this needed functionality.

Struts Action mappings are defined in terms of paths. The name and location of page objects (for example, JSPs) are also defined using paths. Thus, although portlets have their own form of URI, 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 using the query string on the HTTP URL. Often the actions containing these paths are generated from tags provided by Struts. The most obvious examples of these 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 to support the different types of URIs provided by the IBM Portlet API. This attribute can take the following values:

Examples:
<html:rewrite>


<html:form> (IBM portlets)


<html:form> (Standard portlets)


<html:link> (IBM portlets)


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.
Use a forward


Use a page


Use the portlet tags


Markup support

The Struts tag library has been modified to support the additional markup languages supported by WebSphere Portal. For HTML, the tags that create links have been modified to support portlet URIs. See Create portlet URIs for details. Also, be aware of the restrictions for HTML output described in Markup guidelines.

There might be a cases where the JSPs for a Struts application need to 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 will not generate markup when executed 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.

Use the cHTML tags

Use the WML tags

Table 1. Summary of WML tags for Struts portlets

Tag Description
<wml:cancel/> Renders a WML <postfield> element with a value of cancel.
<wml:card/> Renders a WML card element.
<wml:errors/> Retrieves the set of error messages from the request object with the default key of Action.ERROR_KEY or the value specified by attribute name.
<wml:form/> Does not render any markup, but it is used to scope beans and transactions.
<wml:go/> Renders a WML <go> element.
<wml:head/> Renders a WML <head> element with language attributes extracted from the user's current Locale object, if there is one.
<wml:link/> Renders a WML <a> element as a hyperlink to the specified URL.
<wml:option/> Renders a WML <option> element, representing one of the choices for an enclosing <select> element.
<wml:options/> Renders a set of WML <option> elements, representing possible choices for a <select> element.
<wml:password/> Renders a WML <input> element of type password, populated from the specified value or the specified property of the bean associated with our current form.
<wml:postfield/> Renders a WML <postfield> element.
<wml:rewrite/> Renders a request URI based on exactly the same rules as the link tag does, but without creating the <a> hyperlink.
<wml:select/> Renders a WML <select> element, associated with a bean property specified by our attributes.
<wml:text/> Renders a WML <input> element of type text, populated from the specified value or the specified property of the bean associated with our current form.
<wml:wml/> Renders a <wml> element.


Parent

Struts Portlet Framework

  Sep 2, 2010 10:30:23 AM


+

Search Tips   |   Advanced Search