Searching for some more documentation on net about OGNL and its connection
to WW/Struts2, I think I finally isolated what was causing some confusion in
my case. Since it may useful for some other newbies, here is what works in
the situation from the previous post:

  <s:text name="%{#attr['title']}"/>

This doesn't work:

  <s:text name="#attr['title']"/>

because unlike in <s:properties> and some other tags, in <s:text> %{...}
cannot be omitted. 

This wouldn't work either:

  <s:text name="%{attr['title']}"/>

because unlike variables, for non-root objects in WW and Struts2 prefix #
cannot be omitted.

The reasons become pretty clear after one digs deeper into OGNL in WW/S2...
but let's not make the post too big :)

Regards,
Dj.

-----Original Message-----
From: Djordje Trifunovic [mailto:[EMAIL PROTECTED] 
Sent: Friday, February 02, 2007 10:34 PM
To: 'Struts Users Mailing List'
Subject: RE: [S2] <s:text> issue

Wesley - yes, that's it. Thanks for both clarifying my question and
answering it. :)

Now, this really solves the problem when the property is on value stack. Is
there a way to access other (non-root) objects using this notation? E.g. I
have attribute "title" defined in Tiles, also with a key rather than the
direct text. In the layout I do:

        <tiles:importAttribute name="title" />

Normally, I could access this using #attr['title'], but the same problem
appears with <s:text>. Sure, I can always solve it by putting it value to
stack first before using %{...}, but I'd really like to avoid that step if
it is not necessary.

I would appreciate if you could send me off-list the post about OGNL. 

Thanks!
Dj.

-----Original Message-----
From: Wesley Wannemacher [mailto:[EMAIL PROTECTED] 
Sent: Friday, February 02, 2007 9:12 PM
To: Struts Users Mailing List
Subject: RE: [S2] <s:text> issue

I could be wrong, but you may be misunderstanding the poster's intent. He
has a variable on the value stack that indicates which property key he wants
to retrieve. If my understanding is correct, then I would not really be any
help, but has the OP tried: 

<s:text name="%{myKey}" /> 

?

P.S. I have a post from last week or before where I had a bunch of trouble
understanding OGNL and it might help you if you want it off-list. 

> -----Original Message-----
> From: Ian Roughley [mailto:[EMAIL PROTECTED] 
> Sent: Friday, February 02, 2007 3:07 PM
> To: Struts Users Mailing List
> Subject: Re: [S2] <s:text> issue
> 
> I think you may be confused, you say
> 
> The value of myKey is "some.resource.key", and in the
> property file I have:
> 
>     some.resource.key = Some text
> 
> In fact, "some.resource.key" is the key and "some text" is the value.
> 
> Try -
> 
> <s:text name="some.resource.key" />
> 
> 
> /Ian
> 
> -- 
> From Down & Around, Inc.
> Innovative IT Solutions
> Software Architecture * Design * Development
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> web:      www.fdar.com  
> email     [EMAIL PROTECTED]  
> phone:    617.821.5430
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> 
> 
> Djordje Trifunovic wrote:
> > Hi,
> >
> >  
> >
> > Using Struts2 (2.0.5 snapshot) in a project, I hit the 
> following problem: I
> > have a resource bundle key that I need to use with <s:text> 
> tag to retrieve
> > a text from my resource bundle. The name of the key is in a 
> property myKey
> > in the value stack. The value of myKey is 
> "some.resource.key", and in the
> > property file I have:
> >
> >  
> >
> >     some.resource.key = Some text
> >
> >  
> >
> > I tried:
> >
> >  
> >
> >     <s:text name="#myKey" />
> >
> >  
> >
> > but that doesn't work as I expected. Instead of getting 
> "Some text" on my
> > page, or at least "some.resource.key", I get "#myKey" 
> instead. Just to be
> > sure everything is ok in the value stack, I tried:
> >
> >  
> >
> >     <s:property value="#myKey" />
> >
> >  
> >
> > And that returns "some.resource.key", as expected. Am I 
> missing something
> > here?
> >
> >  
> >
> > Thanks,
> >
> > Djordje Trifunovic
> >
> >  
> >
> > PS. I am sorry if the issue was already discussed. I didn't 
> find it quickly
> > searching through archive.
> >
> >  
> >
> >
> >   
> 
> ---------------------------------------------------------------------
> 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]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to