Perhaps I need to rethink what I am trying to do...
My sitemap is getting to be difficult to manage because I have a lot
of variables which I pass around, so I certainly don't want to
introduce more variables. May of the variables have default values,
but I have found no way of telling the sitemap to use default values
if nothing else is specified. What I wanted was to write an action
called "default-values" which would be called as follows:
<map:act type="default-values">
<map:parameter name="p1" value="default1" />
etc.
</map:act>
My idea was to look up the call stack for the first occurrence of
something called "p1" ( {p1}, {../p1}, {../../p1} etc.) and have my
action return its own variable called "p1" which contained the value
found on the stack or, if there was nothing on the stack, the default
value specified in the action. There would be no fixed references to
a particular level.
An example would be
<map:act type="locale">
<map:act type="default-values">
<map:parameter name="language" value="en" />
...
</map:act>
</map:act>
which would give me "en" as the default language if nothing else had
been specified. All I would be doing would be to access {../language}
read-only from within the action, which is no more than what the
sitemap itself does.
Of course, I may be barking up a gum-tree: if there's a better way of
doing this, I'd be grateful for pointers.
Steve
On 13 Sep 2006, at 09:42, Andrew Stevens wrote:
From: Stephen Winnall <[EMAIL PROTECTED]>
Date: Tue, 12 Sep 2006 15:00:59 +0200
I'm writing an action. It's definition is as follows:
public Map act(Redirector redirector, SourceResolver resolver,
Map objectModel, String source, Parameters parameters) throws
Exception {
...
}
I call the action in the sitemap in a context similar to the
following:
<map:match pattern="**">
<map:match pattern="*.html">
<map:act type="abc">
<map:parameter name="abc-param" value="abc-value" />
<!-- MY ACTION IS HERE -->
<map:act type="def">
<map:parameter name="def-param" value="def-value" />
</map:act>
</map:act>
</map:match>
</map:match>
I want to be able to get at sitemap variables from all context
levels from within my action. That means that in the invocation
of 'def' above, I want to be able to access {def-param}, {../abc-
param}, {../../1} and {../../../1}. As far as have been able to
determine, the parameter "Parameters parameters" of the 'act'
method only contains "def-param".
Can someone point me at how to read the other parameters from
within 'act'?
Define/expect another named parameter in your action, and in the
sitemap specify {../../1} or whatever as its value. e.g.
<map:act type="def">
<map:parameter name="def-param" value="def-value" />
<map:parameter name="other-param" value="{../../1}" />
</map:act>
As you have seen, only the parameters directly inside the map:act
are passed to the action. The values with {../whatever} are a
sitemap notation. Trying to lookup a value from a parent map makes
no sense in the action itself - how would it know in what context
it was used, or if it was even used inside the scope of another
map? Or suppose you inserted another action (e.g. LocaleAction)
into the sitemap between the matcher and your action - if your
action relied on a specific path to the value, it would break as it
would now be looking at the wrong level...
Andrew.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]