you need to read about the value stack. long story short, the VS
stacks (duh) objects. When an expressions like:

"name"

is evaluated, struts will go from the top to the bottom of the stack,
trying to find a "name" field or "getName" method, until one is found.
Different things are placed in the stack, the last action executed is
placed on the stack, the iterator tag pushes the current value into
the stack and so on.

Objects can be put in the stack by name, like the HttpServletRequest
object. Theseobjects are accessed using the "#" notation, like
"#request". The "set" tag can add things to the stack by name(for
example).

About the %{}, this part is confusing, for the sake of saving a few
key strokes. Certain attributes in the tags are expected to be strings
literals, like "id", so you can do:

<s:a id="myid" />

instead of the more verbose, but also correct:

<s:a id="%{'myid'}" />

other attributes are expected to be expressions, so you can do:

<s:property value="#request.something" />

instead of the more verbose, but also correct:

<s:property value="%{#request.something}" />

so how do you know which one is which? look at the tag documentation,
as a general rule, for "id" or "name" attributes I use string
literals, and for anything else I add %{...}, because I cant spent my
insufficient memory remembering which one is which :)

musachy

On Thu, Jul 23, 2009 at 4:01 PM, Mitch Claborn<mi...@claborn.net> wrote:
> I'm a big confused about the syntax in struts tags.  For example, I have
> the following:
>
> <s:set var="category" value="display.category" />
> <s:set var="you_are_here_path" value="#category.path" />
>
> "display" is a property on the action.  The first one does not need the
> #, but the second one does.  Why?  What does the # signify?
>
> Some tags seem to need the ognl construct %{.....}.  What are the rules
> around when this construct is needed as opposed to one of the others above?
>
>
> Mitch
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to