Markup guidelines

 

+

Search Tips   |   Advanced Search

 

One of the goals in writing portlet markup is to provide a consistent, clean, and complete user interface. The portal server page is displayed using skins and themes defined by the portal designer or administrator. For portlets to appear integrated with an organization's portal or user's customized portal, they should generate markup that invokes the generic style classes for portlets, rather than using tags or attributes to specify colors, fonts, or other visual elements.

This section provides information for using HTML, WML, and cHTML markup in your portlet JSPs. Portlets are allowed to render only markup fragments which are then assembled by the portlet framework for a complete page. Portlet output should contain complete, well-structured, and valid markup fragments.

This helps to prevent the portlet's HTML code, for example, from corrupting the portal's aggregated HTML code. You should use a validation tool for your markup, such as the W3C HTML Validation Service or a tool from a markup editor.

These guidelines are based on the JSP coding guidelines for standard portlets and for IBM portlets. See the corresponding best practices guide for the type of portlet you are developing on the WebSphere Portal Zone for complete information about portlet output guidelines.

 

HTML

Use standard HTML. For the official HTML specification, see http://www.w3.org.

Use only HTML fragments. Because portlets contribute to the content of a larger page, they should only provide HTML fragments and should not have <html>, <head>, or <body> tags.

Use only elements that can be rendered properly in an HTML table cell (<td>...</td>). Frames, for example, do not appear when inserted in a table.

Make sure the fragments are well-formed to prevent unbalanced pages. Watch out for unterminated, extraneous, or improperly nested tags. The behavior of pages with improperly terminated tags is unpredictable.

Avoid lengthy, complex HTML. Portlets share a page with others and the more content each portlet generates, the more the browser has to process before it can display anything.

Use portlet classes in the portal server's style sheet, Styles.css. If you hard code the fonts and colors, the portlet's appearance will look out of place when the user changes the page style settings. Portal administrators and users can affect the appearance of the portal by changing the portal theme and the portlet skins. Portlets can pick up on style changes by using styles defined in the portal theme's cascading style sheet (Styles.css).

For example, instead of decorating an <input> element with the style attribute, refer to the theme's input class definition:

<inputclass="portlet-form-button" type="submit">

Portlet style classes are marked with the following comment:

/* Styles used in portlets

This section of the style sheet has a mixture of classic IBM style classes and the standard WSRP style classes. When available, use the WSRP style classes, which are prepended with a portlet- prefix. See CSS Style Definitions in the WSRP specification.

Do not use CSS for absolute positioning. This could defeat the portal features that allow users and administrators to place content on the page.

Limit the size of the portlet output. Portlets contribute a portion of a larger page. The size of the JSPs (in terms of horizontal and vertical span) can determine how the portlet can fit on a page with multiple columns and other portlets. A large portlet forces other portlets off the screen and creates large scrolling regions, resulting in usability issues.

Therefore, when designing a portlet's JSPs, avoid unnecessary layout elements focus the portlet's view on the pertinent information, and consider whether the portlet is intended to be placed on pages with other portlets. In particular, take notice of image size, pre-formatted text (<pre/> tag), and absolute widths on elements, such as tables.

Use Java style comments instead of HTML style. HTML comments remain in the rendered content, adding to the document size and the amount of data that passes to the client. If you use Java style comments within your JSPs, instead, they are removed from the rendered source, along with the rest of the Java code. You must imbed these comments within scriptlets:

<% // this is a comment %>

Make pages fully accessible. To allow portal users with disabilities to be able to use your portlet, the JSPs should be fully enabled for keyboard-only control and other assistive technologies. Follow these general guidelines:

See the IBM Accessibility Center for more information.

URIs, HTML element name attributes, and JavaScript resources must be namespace encoded for named elements to prevent name conflicts with other portlets on the portal page.

For standard portlet API use...

<portlet:namespace/>

For IBM portlet API use...

<portletAPI:encodeNamespace value="function" />

Test the portlet output in different browsers. Check portlet behavior when resizing the page to ensure that your portlet works with different browser sizes. Check portlet behavior when the default browser font is changed; your portlet should handle these situations seamlessly.

Do not draw portlet banners, such as title bars, as they are provided by the portal aggregation.

Minimize dependencies on JavaScript. Because JavaScript implementations and behavior differ widely among browser types and versions, the more your portlet depends on JavaScript, the more browser-dependent your portlet becomes.

Additionally, the more of the page that is rendered using JavaScript, the more difficult it is to maintain and to extend to markups other than HTML.

Also, it is more difficult to namespace encode JavaScript resources and nearly impossible to properly encode (response.encodeUrl()) URLs built using JavaScript.

Do not use pop-ups. Interactions within the portal are state-based, which means that the portal tracks your trail through the pages and portlets. Using the browser's back button, or creating pop-up browser instances containing portlets, can cause the portal to lose track of your current state and cause problems. Other than using JavaScript prompts, there is no safe way to spawn pop-ups within the portal, unless the new link takes you to an external page, outside the portal. The alternative is to link to an external page within a new browser window (using the TARGET attribute on the anchor), so that the user is left within the portal in the original browser window.

Use IFRAMEs with caution. IFRAMEs are an easy way to include external content within a portlet, but undermine the whole portlet principle because the portlet API is just tunneled or side-stepped. Therefore, IFRAMEs should only be used for very special cases, such as surfacing legacy applications.

Other potential issues to consider when using an IFRAME are:

Use JSTL instead of re-inventing common tags. JSTL defines many commonly needed tags for...

 

WML

 

Compact HTML (cHTML)

 

Parent topic

Portlet development reference