Home of: [Atelier "FUJIGURUMA"] >> [PageMixer hosted by SourceForge.net]

SEE "For Readers of English Version",
or Japanese version of this page

Mixing with Struts

About this tutorial

The purpose of this tutorial is to learn how to use PageMixer pre-defiened classes for co-operation with Struts.

This tutorial explains it by the case-study of migration from JSP files of struts-mailreader in Struts to Servlet with PageMixer.

You should see "Mixing with PageMixer" at first, if you have less knowledge about PageMixer.

Source and configuration files for tutorials are placed at "src/demo/struts/src" and "src/demo/struts/war" in distribution.

ATTENTION: Class diagrams and sample source codes shown in this tutorial give higer priority to simpleness of explanation than to exact sameness with distributed source.

I wish you do not confuse between one in this tutorial and another in distribution.

NOTE: This tutorial consists of large HTML pages, because it gives higer priority to information browsability in single page than to page compactness.

Which would you like large one, or not ?

Common for each sections

There are something common for each sections in this tutorial.

I18N/L10N of HTML contents

In Struts and JSP combination, "bean:message" TagLib is used for message internationalization(I18N) and localization(L10N). In other hand, I18N/L10N is done not per message but per page with PageMixer framework.

Please see "Render locale sensitively" tutorial for detail.

Sample code for filter creation

Almost all filters explained in this tutorial are part of "StdTailFilter" provided by PageMixer framework since 3.1 for convenience, so there is no code, which is shown in each sections, under "src/demo/struts/src" in distribution.

In addition to that, StdTailFilter is used automatically by PageServlets for PageMixer/Struts co-operation, so you should not specify something to use StdTailFilter in deployment descriptor(web.xml). Please see StrutsFilterFactory for detail.

Local resource location

Resource location specified in HTML page is treated as:

relative to requested URI:

if location does not have leading slash("/").

For example, this prevents HTML template page, which is for 404(Not Found) error, from include link for top page, because you can not determine relativity to requested URI before running.

relative to base URI:

if location does not have leading slash("/"), and HTML page has base tag.

Problemn of this case is as same as one of "requested URI relative" case, if base has as same value as requested one, and ordinaly it seems to be so.

You can solve this problem by insetting context root path into base tag.

absolute in Servlet container:

if location has leading slash("/").

This way makes web application as non portable one, because it comes to depend on deployment context.

In co-operation with Struts, PageMixer framework insets location of Servlet context root into href attribute of base HTML tag which appears in token sequence.

This allows you to specify location of application local resources, except ones of Struts Actions, relatively not to requested URI but to Servlet context root. Though, location of Struts Actions must be as same as ones specified in configuration file(s) exactly.

ATTENTION: PageMixer framework does not insert base tag into HTML page automatically, so you should describe it explicitly.


Things not yet well documented:

"cancel" button in form

If you place "cancel" button in form corresponded to "ActionForm", you must specify "name" attribute of it ("input" tag) as "org.apache.struts.taglib.html.CANCEL" (defined as "org.apache.struts.taglib.html.Constants#CANCEL_PROPERTY") for correct behavior.

In other words, you must specify "name" attribute of "input" tag as "org.apache.struts.taglib.html.CANCEL" if you want translate from JSP file which uses "CancelTag"("html:cancel") TagLib of Struts.

Table of contents

Overview of migration

overview of migration from JSP files of struts-mailreader in Struts to Servlet with PageMixer.

Inset URI

inset URI corresponded to mapped "Action".

Handle errors

handle error information of Struts.

Inset Bean

inset field values of Bean.

Trim by value of Bean

eliminate part of HTML page by field value of Bean.


iterate part of HTML page by field value of Bean.

Complex filterring

example of more complex behavior.

Configure Servlet

configuration of Servlet to replace with JSP.

Configure Struts

(re-)configuration of Struts.