March 1, 2021
Hot Topics:

Reusable Syndicated Media Portlets: An Example of Simplified Content Presentation

  • By Scott Nelson
  • Send Email »
  • More Articles »

This time, you have set multiValued to false for the sake of simplicity. It is entirely possible to have multiple content types using this approach, though if all of the possibilities were covered you will never finish reading this article in time to use it.

Now,make some minor additions to your controller to allow for multiple presentation options. In the earlier examples, you skipped the forward (or view, to be more generic) definition. Here, you will include the forward declaration showing an additional parameter added for contentType:

@Jpf.Action(forwards = { @Jpf.Forward(name = "default",
   path = "index.jsp", actionOutputs =
   { @Jpf.ActionOutput(name = "contentDocList",
     type = java.util.List.class, required = false),
     @Jpf.ActionOutput(name = "contentType",
     type = java.lang.String.class, required = true) }) })

Then, you will add one line to pass this value through from the portlet configuration file to the JSP:

   preferences.getValue("contentType", null));

Because you have a good chunk of code in creating the JSP, declaring the variables, and looping through the content, you can use an include for just the part that is different, rather than writing a whole new JSP that would be mostly a copy/paste from your first one. Before you go into the while loop, you can use the content type to determine your format path:

formatPath = (String)pageContext.getAttribute("contentType");

Then, pick the include that has your format-specific handling:

<% if(formatPath.equals("news")){%>
   <%@ include file="news.jspf" %>
<% }if(formatPath.equals("weather")){ %>
   <%@ include file="weather.jspf" %>
<% }if(formatPath.equals("stocks")){ %>
   <%@ include file="stocks.jspf" %><%} %>

Yes, weather is there and you haven't coded for it yet. But, you don't need to code for it. You just need to create a portlet definition for it and so long as your delegate can fetch weather, you can show it (or any other content format) based on the display templates in the includes. Although a new presentation layout will require adding a new include, and a new portlet, that is one JSP fragment and one configuration file to go from four content portlets to five, rather than the usual addition of four (or more) complete objects. If the weather is nice, you'll have more time to enjoy it.

WebLogic-Specific Note: The more recent versions of Workshop/WorkSpace studio that use AppXRay for validation require a patch for validating .jspf files as used in this article. If you have a non-commercial developer version, you will need to turn off JSP validation or use .jsp includes that take request parameters.


The example detailed in this article dealt with multiple presentations of multiple content types that can be managed more by configuration than new development. This approach is extensible to other content presentation solutions. A more complex solution could include multiple forward methods to provide content search or filtering, for example. There are also simpler uses for this approach, such as storing parameters for content management integration as preferences that would require no additional includes. If your portal framework supports creating new configurations at run time, you don't even need additional portlet definition files.

Where the reuse of patterns can reduce the time and risk of designing an application, finding opportunities to reuse code not only leads to faster development time, it reduces maintenance while improving reliability.

About the Author

Scott Nelson is a Senior Principal Consultant with 12 years of experience designing, developing, and maintaining web-based applications for manufacturing, pharmaceutical, financial services, non-profit organizations, and real estate agencies for use by employees, customers, vendors, franchisees, executive management, and others who use a browser. He also blogs all of the funny emails forwarded to him at Frequently Unasked Questions.

Page 3 of 3

This article was originally published on July 22, 2008

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date