You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

Overview

Packages are a way to group Actions, Results, Result Types, Interceptors and Stacks into a logical unit that shares a common configuration. Packages are similiar to objects in that they can be extended and have individual parts overridden by "sub" packages.

Packages

The package element has one required attribute, "name", which acts as the key for later reference to this package. The "extends" attribute is optional and allows one package to inherit the configuration of one or more previous packages including all interceptor, interceptor-stack, and action configurations. Note that the configuration file is processed sequentially down the document, so the package referenced by an "extends" should be defined above the package which extends it. The "abstract" optional attribute allows you to make a package abstract, which will allow you to extend from it without the action configurations defined in the abstract package actually being available at runtime.

Attribute

Required

Description

name

yes

key to for other packages to reference

extends

no

inherits package behavior of the package it extends

namespace

no

see Namespaces

abstract

no

declares package to be abstract (no action configurations required in package)

Sample usage of packages in xwork.xml
    <package name="bar" extends="webwork-default" namespace="/foo/bar">
        <interceptors>
            <interceptor-stack name="barDefaultStack">
                <interceptor-ref name="debugStack"/>
                <interceptor-ref name="defaultStack"/>
            </interceptor-stack>
        </interceptors>

        <action name="Bar" class="com.opensymphony.xwork.SimpleAction">
            <interceptor-ref name="barDefaultStack"/>
        </action>

        <action name="TestInterceptorParamInheritance" class="com.opensymphony.xwork.SimpleAction">
            <interceptor-ref name="test">
                <param name="expectedFoo">expectedFoo</param>
            </interceptor-ref>
        </action>

        <action name="TestInterceptorParamInehritanceOverride" class="com.opensymphony.xwork.SimpleAction">
            <interceptor-ref name="test">
                <param name="foo">foo123</param>
                <param name="expectedFoo">foo123</param>
            </interceptor-ref>
        </action>
    </package>

    <package name="abstractPackage" namespace="/abstract" abstract="true">
        <action name="test" class="com.opensymphony.xwork.SimpleAction"/>
    </package>

    <package name="nonAbstractPackage" extends="abstractPackage" namespace="/nonAbstract"/>

    <package name="baz" extends="default" namespace="baz">
        <action name="commandTest" class="com.opensymphony.xwork.SimpleAction">
            <param name="foo">123</param>
            <result name="error" type="chain">
                <param name="actionName">bar</param>
            </result>
            <interceptor-ref name="static-params"/>
        </action>
        <action name="myCommand" class="com.opensymphony.xwork.SimpleAction" method="commandMethod">
            <param name="bar">456</param>
            <result name="success" type="chain">
                <param name="actionName">foo</param>
            </result>
            <interceptor-ref name="logger"/>
        </action>
    </package>

    <package name="multipleInheritance" extends="default,abstractPackage,bar" namespace="multipleInheritance">
        <action name="testMultipleInheritance" class="com.opensymphony.xwork.SimpleAction">
            <result name="success" type="chain">
                <param name="actionName">foo</param>
            </result>
            <interceptor-ref name="barDefaultStack"/>
        </action>
    </package>
  • No labels