<<

. 58
( 87 .)



>>

b. In the Import page navigate to the PortalStrutsBlank.war
¬le and select New for Project.
c. In the New Web Project page, enter Poll Struts for Project Name
and select Finish to create the project.
d. Select Finish from the WAR ¬le page to complete the import
(see Figure 18-1).




Figure 18-1 Importing the Struts Portlet Framework.
P1: FCH
WY009-18 WY009-BenNatan-v1.cls May 11, 2004 14:51




Struts Portlet Framework 347


N O T E After the import completes if you get the following error Attribute
“bundle” must be declared for element type “¬eld,” in the validation.xml
¬le, then remove the attribute from this ¬le.

2. Add the portal jar ¬les to the project build classpath. To do so,
perform the following steps:
a. Open the properties on the newly created project by right-clicking
the project in the Navigator pane.
b. Select Properties from the pop-up menu.
c. Select Java Build Path and then the Libraries tab.
d. Select Add Variable, then select WPS V5 PLUGINDIR in the New
Variable classpath entry, and click Extend. Select
portlet-api.jar and select OK.
e. Select Add Variable, then select WPS V5 PLUGINDIR in the New
Variable classpath entry, and click Extend. Select wps.jar and
select OK.
f. Select Add Variable, then select WPS V5 PLUGINDIR in the New
Variable classpath entry, and click Extend. Select wpsportlets
.jar and select OK.
g. Select Add Variable, then select WAS 50 PLUGINDIR in the New
Variable classpath entry, and click Extend. Expand the lib
directory, select dynacache.jar and select OK.
h. Select OK to save the property changes.
3. Change the newly created project to J2EE 1.3. To do so, follow these
steps:
a. Open the properties on the newly created project by right-clicking
the project in the Navigator pane.
b. Select Properties from the pop-up menu.
c. Select Web and then change J2EE Level to 1.3.
d. Click OK to save the change.
4. Add portlet.tld to the tag lib folder in the new project. To do so,
follow these steps:
a. Right-click the tld folder in the project.
b. Select Import and then File System.
c. On the File System page browse to ¬nd the <wp-root>\shared\
app\WEB-INF\tld directory and select OK. Highlight (do not
click the check box of) tld, in the right pane.
P1: FCH
WY009-18 WY009-BenNatan-v1.cls May 11, 2004 14:51




348 Chapter 18


d. Click the check box for portlet.tld.
e. Finally, click Finish.
5. If you see a warning that states “Web context root should start with
slash(/) character for portlet application debugging” open the
properties on the newly created project by right-clicking the project
in the Navigator pane. Then select Properties from the pop-up menu.
Select Web and then add a / to the Context Root.
6. Add the JavaServer Pages Standard Tag Libraries. Add
standard.jar and jstl.jar to the portlet project™s lib folder
(WebContent\WEB-INF\lib). These tag libraries are used to
retrieve language-speci¬c text from resource bundles based on the
user™s locale. The tag libraries are open-source code available from
Jakarta at (http://jakarta.apache.org/).


Web Deployment Descriptor
A default Web deployment descriptor is provided with the Portal Struts
Framework. You need to update it for the Poll portlet. Edit the web.xml
¬le and change the <display-name> element to a name for this portlet
such as Poll Struts. The ID attribute of the servlet element must be unique in
your deployed Web application. Change this value to a unique string such as
the Poll Portlet class name, com.ibm.sample.portlet.poll.portlet
.PollPortlet. Change the <servlet-class> element to the portlet
class name, com.ibm.sample.portlet.poll.portlet.PollPortlet.
Struts Portlet Framework takes advantage of struts module support to
provide both mode and device (markup) differentiation for the Struts
con¬guration. When using modules, an application™s con¬guration infor-
mation and directory structure are separated by module. Therefore, instead
of a single struts-config.xml ¬le for the application, you have multi-
ple control ¬les within separate directory structure, identi¬ed by module-
relative portions of the application URI. The search path is used to determine
the module and struts-config.xml ¬le to use. It also determines the
base directory for locating JSPs.
Add the following initialization parameter to set the search path to take
markup name and mode into consideration when searching for modules.
<init-param>
<param-name>ModuleSearchPath</param-name>
<param-value>markupName, mode</param-value>
</init-param>

You will need to create two modules for this application, one for edit mode
and one for con¬gure mode. The view mode is con¬gured through the base
P1: FCH
WY009-18 WY009-BenNatan-v1.cls May 11, 2004 14:51




Struts Portlet Framework 349


struts con¬guration. The two modules are de¬ned as init parameters in the
form: /config/<device>/<mode>. The value associated with each of
these parameters speci¬es the name and location of the struts con¬guration
¬le.
<init-param>
<param-name>config/html/configure</param-name>
<param-value>/WEB-INF/html/configure/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>config/html/edit</param-name>
<param-value>/WEB-INF/html/edit/struts-config.xml</param-value>
</init-param>

Finally, update the welcome ¬le list. The Struts Portlet Framework lets
you specify the initial view for each device/mode combination. This is
speci¬ed through the welcome ¬le list. The default welcome ¬le list only
provides a welcome ¬le speci¬cation for the view mode.
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>html/edit/index.jsp</welcome-file>
<welcome-file>html/configure/index.jsp</welcome-file>
</welcome-file-list>




Portlet Deployment Descriptor
The portlet deployment descriptor must also be updated. The changes to
both descriptors as well as the build path are necessary since we created a
Web project during the WAR ¬le import. Previously, we created a portlet
application project using the Creation Wizard from the portal toolkit. Part
of that process created complete deployment descriptors and set the correct
build path.
Edit the portlet.xml ¬le and make the following changes.
Change the uid attribute of the <portlet-app> element to a
unique identi¬er such as “com.ibm.sample.portlet.poll
.portlet.PollPortlet:1”
Change the <portlet-app-name> element to a meaningful name
such as Poll (Struts) Application.
Change the href attribute of the <portlet> element to reference
the servlet id that you speci¬ed in the Web deployment descriptor
appended after “WEB-INF/web.xml”.
Change the <portlet-name> element to a meaningful name such
as Poll (Struts).
P1: FCH
WY009-18 WY009-BenNatan-v1.cls May 11, 2004 14:51




350 Chapter 18


Add markup elements for con¬gure and edit modes as well as the
default view mode.
Change the uid attribute of the <concrete-portlet-app>
element to a unique identi¬er such as com.ibm.sample.portlet
.poll.portlet.PollPortlet:1.1.
Change both the <portlet-app-name> element and the
<portlet-name> element for the concrete portlet application
to meaningful names such as Poll (Struts) Applications and Poll
(Struts).
Finally, specify meaningful values for the language-speci¬c
attributes for title, short title, description, and key words.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE portlet-app-def PUBLIC "-//IBM//DTD Portlet Application
1.1//EN" "portlet_1.1.dtd">
<portlet-app-def>
<portlet-app
uid="com.ibm.sample.portlet.poll.portlet.PollPortlet:1"
major-version="1" minor-version="0">
<portlet-app-name>Poll (Struts) Application</portlet-app-name>
<portlet id="Portlet_1"
href="WEB-
INF/web.xml#com.ibm.sample.portlet.poll.portlet.PollPortlet"
major-version="1" minor-version="0">
<portlet-name>Struts Blank</portlet-name>
<cache>
<expires>0</expires>
<shared>NO</shared>
</cache>
<allows>
<maximized/>
<minimized/>
</allows>
<supports>
<markup name="html">
<view />
<configure />
<edit />
</markup>
</supports>
</portlet>
</portlet-app>
<concrete-portlet-app
uid="com.ibm.sample.portlet.poll.portlet.PollPortlet:1.1">
<portlet-app-name>Poll (Struts) Application</portlet-app-name>
<concrete-portlet href="#Portlet_1">
<portlet-name>Poll (Struts)</portlet-name>
<default-locale>en</default-locale>
P1: FCH
WY009-18 WY009-BenNatan-v1.cls May 11, 2004 14:51




Struts Portlet Framework 351


<language locale="en">
<title>Poll (Struts)</title>
<title-short>Poll (Struts)</title-short>
<description>
Poll portlet using the struts portlet framework
</description>
<keywords>Poll, Struts</keywords>
</language>
<config-param>
<param-name>FilterChain</param-name>
<param-value>StrutsTranscoding</param-value>
</config-param>
</concrete-portlet>
</concrete-portlet-app>
</portlet-app-def>




Struts Con¬guration Files
The struts con¬guration ¬le (struts-config.xml) contains the applica-
tion de¬nitions that the struts framework uses for control, navigation, and
con¬guration settings, including form beans that are needed. The mod-
ule initialization parameters de¬ned in the deployment descriptor spec-
i¬ed two module-speci¬c struts con¬guration ¬les. Along with the base
struts con¬guration ¬le that is located in the WebContent/WEB-INF di-
rectory, you need to create two new struts-config.xml ¬les: one in
the WebContent /WEB-INF/html/configure directory for con¬gure
mode and one in the WebContent/WEB-INF/html/edit directory for
edit mode.
The struts con¬guration de¬nitions map fairly well to our existing Poll
portlet. Our implementation already has Action classes that provide the
application function that is expected by the struts Action classes. The class
de¬nition and method signature will change somewhat but for the most part
the implementation of these classes remains the same. With the exception
of changes needed for portlet URL addressability, we do not need to change
the existing JSPs. In general, the View classes were associated with Actions
and simply invoked the appropriate JSP. In the struts con¬guration the JSPs
are de¬ned and in cases associated with actions. Our Poll portlet used form
data beans for user input in con¬gure mode and the struts implementation
de¬nes the form data beans as well.

Struts Con¬guration in Portlet View Mode
The portlet edit, view, and help modes are mapped to struts modules. The

<<

. 58
( 87 .)



>>