Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In order to use the Convention plugin, you first need to add the JAR file to the WEB-INF/lib directory of your application (if you package your actions in jar files, make sure that struts.convention.action. disableJarScanning is set to true).

Converting a Codebehind based application to Convention

...

By default the Convention plugin will not scan jar files for actions. To enable jar scanning, two things need to be done:

...

For a jar to be scanned, it's URL needs to match at least one of the regular expressions in struts.convention.action

...

.includeJars. In this example myjar1.jar and myjar2.jar will be scanned:

Code Block
xml
xml

<constant name="struts.convention.action.includeJars" value=".*/myjar1

...

.*?jar(!/)?,.*/myjar2

...

*?jar(!/)?"

...

Note that the regular expression will be evaluated against the URL of the jar, and not the

...

file name, the jar URL can contain a path to the jar file and a trailing "!/".

Automatic configuration reloading

...

  1. I get an error like "There is no Action mapped for namespace /orders and action name view.". This means that the URL /orders/view.action is not mapping to any action class. Check the namespace and the name of the action.
  2. I get an error like "No result defined for action "my.example.actions.orders.ViewAction and result success". This means that the action was mapped to the right URL, but the Convention plugin was unable to find a success result for it. Check that the result file exists, like /WEB-INF/content/orders/view-success.jsp.
  3. I get lots of errors like "java.lang.Exception: Could not load org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.class". This happens when struts.convention.action.disableJarScanning is false, and struts.convention.action.includeJars is matching jar URLs from external jars.

...

Scan jar files for actions

Name

Default Value

Description

struts.convention.action.disableJarScanning

true

struts.convention.action.includeJars

 

Comma separated list of regular expressions of jar URLs to be scanned (ignored unless struts.convention.action.disableJarScanning is false)

struts.convention.action.packages

 

An optional list of action packages that this should create configuration for (they don't need to match a locator pattern)

struts.convention.result.path

/WEB-INF/content/

Directory where templates are located

struts.convention.result.flatLayout

true

If set to false, the result can be put in its own directory: resultsRoot/namespace/actionName/result.extension

struts.convention.action.suffix

Action

Suffix used to find actions based on class names

struts.convention.action.disableScanning

false

Scan packages for actions

struts.convention.action.mapAllMatches

false

Create action mappings, even if no @Action is found

struts.convention.action.checkImplementsAction

true

Check if an action implements com.opensymphony.xwork2.Action to create an action mapping

struts.convention.default.parent.package

convention-default

Default parent package for action mappins

struts.convention.action.name.lowercase

true

Convert action name to lowercase

struts.convention.action.name.separator

-

Separator used to build the action name, MyAction -> my-action. This character is also used as the separator between the action name and the result in templates, like action-result.jsp

struts.convention.package.locators

action,actions,struts,struts2

Packages whose name end with one of these strings will be scanned for actions

struts.convention.package.locators.disable

false

Disable the scanning of packages based on package locators

struts.convention.exclude.packages

org.apache.struts.*,
org.apache.struts2.*,
org.springframework.web.struts.*,
org.springframework.web.struts2.*,
org.hibernate.*

Packages excluded from the action scanning

struts.convention.package.locators.basePackage

 

If set, only packages that start with its value will be scanned for actions

struts.convention.relative.result.types

dispatcher,velocity,freemarker

The list of result types that can have locations that are relative and the result location (which is the resultPath plus the namespace) prepended to them

struts.convention.redirect.to.slash

true

A boolean parameter that controls whether or not this will handle unknown actions in the same manner as Apache, Tomcat and other web servers. This handling will send back a redirect for URLs such as /foo to /foo/ if there doesn't exist an action that responds to /foo