Programming Thoughts
Struts 2 - Pagination
Different Interceptor Stacks

Obvious but not part of the default

Those who've come this far have already noticed at least two roles for Actions: processing forms and displaying data. The officially recommended Post/Redirect/Get practically forces this. Yet the Struts 2 baseline struts-default.xml only expects defaultStack as the interceptor stack to be generally used. This article will examine one for each role.

Custom interceptors

The configuration fragments in this article refers to custom interceptors. The description for each is below.

Name Purpose Description
formRetrieve Retrieve a stored form from session for display. Preserving forms and More Form Injection
formStore Store a processed form into session so it's preserved in a redirect. Preserving forms and More Form Injection
messageAmalgamation Copy messages from previous Actions to the last when dispatching from one to another. Alternate solution
messageRetrieve Retrieve stored messages from session for display. Preserving user messages
messageStore Store messages into session so it's preserved in a redirect. Preserving user messages

Abstract interceptor stacks

Interceptor stacks can contain other interceptor stacks and the custom stacks in later sections contain the ones below. They're based on the default stack and refer to the built-in interceptors.

<interceptor-stack name="CommonStackTop"> </interceptor-stack> <!-- This is the default stack minus the exception, validation and workflow interceptor --> <interceptor-stack name="CommonStackBottom"> <interceptor-ref name="alias"/> <interceptor-ref name="servletConfig"/> <interceptor-ref name="i18n"/> <interceptor-ref name="prepare"/> <interceptor-ref name="chain"/> <interceptor-ref name="debugging"/> <interceptor-ref name="scopedModelDriven"/> <interceptor-ref name="modelDriven"/> <interceptor-ref name="fileUpload"/> <interceptor-ref name="checkbox"/> <interceptor-ref name="multiselect"/> <interceptor-ref name="staticParams"/> <interceptor-ref name="actionMappingParams"/> <interceptor-ref name="params"> <param name="excludeParams">dojo\..*,^struts\..*</param> </interceptor-ref> <interceptor-ref name="conversionError"/> </interceptor-stack>

Viewer interceptor stacks

Viewer Actions should be concerned with retrieving data for display in its JSP page and dispatching to that JSP, not processing a job and deciding the next step. This includes forms and messages stored across a redirect whilst validator and worflow interceptors can be skipped. The interceptor stack is shown below.

<interceptor-stack name="ViewStack"> <interceptor-ref name="CommonStackTop" /> <interceptor-ref name="formRetrieve" /> <interceptor-ref name="messageRetrieve" /> <interceptor-ref name="messageAmalgamation" /> <interceptor-ref name="CommonStackBottom" /> </interceptor-stack>

Form processing interceptor stacks

Form processing Actions process a task and redirects to a viewer Action to display results. The interceptor stack is shown below.

<interceptor-stack name="FormDrivenStack"> <interceptor-ref name="CommonStackTop" /> <interceptor-ref name="formStore" /> <interceptor-ref name="messageStore" /> <interceptor-ref name="CommonStackBottom" /> <interceptor-ref name="validation"> <param name="excludeMethods">input,back,cancel,browse</param> </interceptor-ref> <interceptor-ref name="workflow"> <param name="excludeMethods">input,back,cancel,browse</param> </interceptor-ref> </interceptor-stack>

Next part

Continued in Example.