Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0
Info

The example code for this tutorial, exclude_parameters, is available for checkout at https://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2examples/Image Removed.

Introduction

...

Consider this code which creates a form:

html
Code Block
html
titleStruts 2 Form Tags
html

<s:form action="save" method="post">
<s:textfield key="personBean.firstName" /> 
<s:textfield key="personBean.lastName" /> 
<s:textfield key="personBean.email" />
<s:textfield key="personBean.phoneNumber" />
<s:select key="personBean.sport" list="sports" />
<s:radio key="personBean.gender" list="genders" />
<s:select key="personBean.residency" list="states" listKey="stateAbbr" listValue="stateName" />
<s:checkbox key="personBean.over21" />
<s:checkboxlist key="personBean.carModels" list="carModelsAvailable" />
<s:submit key="submit" />
</s:form>

The s:submit tag will create a submit button with a name of submit. Since the Action class probably doesn't have a setSubmit(String name) method you will see the following log messages (only if Struts development mode is set to true):

Code Block
plainplain
titleLog Messages
plain

Dec 31, 2012 3:43:53 PM 
com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
WARNING: Parameter [submit] is not on the excludeParams list of patterns and will be appended to action!

Dec 31, 2012 3:43:53 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
SEVERE: Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'submit' on 'class org.apache.struts.edit.action.EditAction: Error setting expression 'submit' with value ['Save Changes', ]

...

To exclude specific parameters from being processed by the Struts 2 framework you need to add those parameter names to the list of excluded parameters. One way to do this is by adding those parameter names to the collection of excludedParams for the Parameters interceptor. You can do this by modifying the Parameters interceptor in setting up the stack of interceptors used by your Struts 2 application. For example:

xml
Code Block
xml
titleSetup Interceptor Stack To Exclude submit Parameter
xml

<interceptors>
  <interceptor-stack name="appDefault">
    <interceptor-ref name="defaultStack">
       <param name="exception.logEnabled">true</param>
       <param name="exception.logLevel">ERROR</param>
       <param name="params.excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*,submit</param>
    </interceptor-ref>
  </interceptor-stack>
</interceptors>
		
<default-interceptor-ref name="appDefault" />

...