webwork / docs / wikidocs / Namespaces.html

        <title>WebWork 2 : Namespaces</title>
	    <link rel="stylesheet" href="styles/site.css" type="text/css" />
        <META http-equiv="Content-Type" content="text/html; charset=UTF-8">	    

	    <table class="pagecontent" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff">
			    <td valign="top" class="pagebody">
				    <div class="pageheader">
					    <span class="pagetitle">
                            WebWork 2 : Namespaces
				    <div class="pagesubheading">
					    This page last changed on Jun 17, 2004 by <font color="#0050B2">casey</font>.

				    <p class="paragraph"><h3 style="margin: 4px 0px 4px 0px;" class="heading3"><a name="Namespaces-Namespaces"> Namespaces</a></h3></p>The namespace attribute allows you to segregate action configurations into namespaces, so that you may use the same action alias in more than one namespace with different classes, parameters, etc. This is in contrast to Webwork 1.x, where all action names and aliases were global and could not be re-used in an application. The default namespace, which is &quot;&quot; (an empty string) is used as a &quot;catch-all&quot; namespace, so if an action configuration is not found in a specified namespace, the default namespace will also be searched. This allows you to have global action configurations outside of the &quot;extends&quot; hierarchy, as well as to allow the previous Webwork 1.x behavior by not specifying namespaces. It is also intended that the namespace functionality can be used for security, for instance by having the path before the action name be used as the namespace by the Webwork 2.0 ServletDispatcher, thus allowing the use of J2EE declarative security on paths to be easily implemented and maintained. <p class="paragraph"><h4 class="heading4"><a name="Namespaces-Namespaceexample"> Namespace example</a></h4></p><div class="code"><div class="codeContent">
<pre>&lt;<span class="java&#45;keyword">package</span> name=<span class="java&#45;quote">&quot;<span class="java&#45;keyword">default</span>&quot;</span>&gt;&#10;&#10;    &lt;action name=<span class="java&#45;quote">&quot;foo&quot;</span> class=<span class="java&#45;quote">&quot;mypackage.simpleAction&gt;&#10;        &lt;result name=&quot;</span>success<span class="java&#45;quote">&quot; type=&quot;</span>dispatcher<span class="java&#45;quote">&quot;&gt;greeting.jsp&lt;/result&gt;&#10;    &lt;/action&gt;&#10;    &lt;action name=&quot;</span>bar<span class="java&#45;quote">&quot; class=&quot;</span>mypackage.simpleAction<span class="java&#45;quote">&quot;&gt; &#10;        &lt;result name=&quot;</span>success<span class="java&#45;quote">&quot; type=&quot;</span>dispatcher<span class="java&#45;quote">&quot;&gt;bar1.jsp&lt;/result&gt; &#10;    &lt;/action&gt; &#10;&#10;&lt;/<span class="java&#45;keyword">package</span>&gt;&#10;&#10;&#10;&lt;<span class="java&#45;keyword">package</span> name=&quot;</span>mypackage<span class="java&#45;quote">&quot; namespace=&quot;</span>/barspace<span class="java&#45;quote">&quot;&gt; &#10;&#10;    &lt;action name=&quot;</span>bar<span class="java&#45;quote">&quot; class=&quot;</span>mypackage.simpleAction<span class="java&#45;quote">&quot;&gt; &#10;        &lt;result name=&quot;</span>success<span class="java&#45;quote">&quot; type=&quot;</span>dispatcher&quot;&gt;bar2.jsp&lt;/result&gt; &#10;    &lt;/action&gt; &#10;&#10;&lt;/<span class="java&#45;keyword">package</span>&gt;</pre>
If a request for /barspace/bar.action is made, then the package named mypackage is searched and the bar action is executed.  If success is returned, then bar2.jsp is displayed. <p class="paragraph"><ins class="inserted">Note:</ins> If a request is made to /barspace/foo.action, the action foo will be searched for in a namespace of /barspace.  If the action is not found, the action will then be searched for in the default namespace.  Unless specified, the default namespace will be &quot;&quot;.  In our example above, their is no action foo in the namespace /barspace, therefore the default will be searched and /foo.action will be executed.</p>

	    <table border="0" cellpadding="0" cellspacing="0" width="100%">
				<td height="12" background="border/border_bottom.gif"><img src="border/spacer.gif" width="1" height="1" border="0"/></td>
			    <td align="center"><font color="grey">Document generated by Confluence on Oct 18, 2004 00:08</font></td>