November 27, 2014
Hot Topics:

Reusable Syndicated Media Portlets: An Example of Simplified Content Presentation

  • July 22, 2008
  • By Scott Nelson
  • Send Email »
  • More Articles »

And finally, a basic portlet config file (again, using the WLP syntax for the sake of speed):

<netuix:portlet definitionLabel="simpleExample"
                title="Simple Example">
   <netuix:titlebar/>
   <netuix:content>
      <netuix:pageflowContent
              contentUri="/portlets/syndicatedContent/
                          SyndicatedContentController.jpf"/>
   </netuix:content>
</netuix:portlet>

So far, you haven't done anything special because you have only one type of content. But, what if your audience becomes worldlier and wants to know about what is going on in the world outside of technology? Often, that would result in writing all of the above all over again, except the delegate (and only because it takes a content source parameter; otherwise, you'd need another delegate, too). Instead, tweak what you already have by adding some very minor changes to your original components.

First, you will add a preference value to your first portlet definition to indicate the content source:

<netuix:portlet definitionLabel="techNews" title="Tech News">
   <netuix:titlebar/>
   <netuix:content>
      <netuix:pageflowContent
              contentUri="/portlets/syndicatedContent/
                          SyndicatedContentController.jpf"/>
   </netuix:content>
   <netuix:preference description="Content Source Key"
                      modifiable="true"
                      multiValued="true"
                      name="contentSources"
                      value="techContent"/>
</netuix:portlet>

Note that you have set mutliValued to true so that you can aggregate content sources with the same presentation if you want to at some later time.

Next, create a second definition file for the new content source:

<netuix:portlet definitionLabel="worldNews"
                title="World News">
   <netuix:titlebar/>
   <netuix:content>
      <netuix:pageflowContent contentUri="/portlets/
         syndicatedContent/SyndicatedContentController.jpf"/>
   </netuix:content>
   <netuix:preference description="Content Source Key"
                      modifiable="true"
                      multiValued="true"
                      name="contentSources"
                      value="worldNews"/>

Some portal frameworks (including WLP) allow for the run-time creation of portlet definition through an administration console, a viable alternative if available and (once you are done) will allow the addition of new content without redeploying the portal application, only updating the source application (assuming you have segregated your deployments between model and view). This is why you have modifiable set to true.

Next, you will modify your controller to read the contentSource preference and pass it as your parameter to the delegate:

backingContext =
   PortletBackingContext.getPortletBackingContext(getRequest());
preferences = backingContext.getPortletPreferences(getRequest());
contentPrefs = preferences.getValues("contentSources", null);

for(int i=0; i < contentPrefs.length; i++)
{
   strContent =
      ContentStub.getSyndicatedContent(contentPrefs[i].trim());
   //the trim operation is necessary due to some quirks
   //in how multiple preferences are stored in WLP
   if(strContent!=null){contentDocList.add(strContent);}
}

Now, rather than creating a whole new set of classes to provide World News in addition to Tech News, you have achieved the same with six lines of code and one configuration file.



Click here for a larger image.

Figure 1: Two Content Portlets from One Set of Code

Multiple Views with the Same Solution

You know that our portal content won't stop at news headlines. If your portal does well, you may want to track the value of stocks you bought with your bonuses for adding more content with less code. Of course, stock prices have a different layout than headlines, so you need a new set of code to add that, right? That's either obviously rhetorical or you skipped to this section to see whether the article was worth finishing. You can add stock prices to your content and then you can decide.

Because there will be multiple presentations of content, you need a way to define what type of content you will show. Go back to your first two portlet definition files to add one more preference:

<netuix:preference description="Presentation Style"
                   modifiable="true"
                   multiValued="false"
                   name="contentType"
                   value="news"/>




Page 2 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

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

Sitemap | Contact Us

Rocket Fuel