Monday, December 23, 2013

OpenPortal - Calling JSP from a Portlet

I recently got stuck on Chapter 3 of Cameron McKenzie's Portlet Programming book.  Since it took me a while to figure this out and because I wasn't able to find anything of much help online, I thought I'd share what I did.

Note: The following solution was tested on GlassFish 4 using the OpenPortal Portlet Container.

Basically I needed to modify the web.xml file to the following:
<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE web-app PUBLIC 
  "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
  "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app id="WebApp_ID">
  <display-name>JSPDisplay-Portlet</display-name>

  <taglib id="PortletTLD">
    <taglib-uri>http://java.sun.com/portlet</taglib-uri>
    <taglib-location>/WEB-INF/sun-portlet.tld</taglib-location>
  </taglib>

</web-app>
The above code was derived from page 54 of Cameron McKenzie's book.  Cameron, however, used /WEB-INF/tld/std-portlet.tld as the body of the taglib-location element.  That is, in Cameron's book this is what he has:
<taglib-location>/WEB-INF/tld/std-portlet.tld</taglib-location>
I obtained the sun-portlet.tld file from OpenPortal's sample portlet project, WelcomePortlet. 

Note: You'll also need to add the portlet.jar and portlet-container.jar to the build path.

No comments:

Post a Comment