You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "lei.java@gmail.com" <le...@gmail.com> on 2008/01/06 18:08:52 UTC

Tags and variable attributes

Hi all,

I have an action property holding a key in a properties file. In the view
page, I like to display the value of the key. Since struts tags only accept
plain text as attribute values, I can only render the key in the view like
this:
<s:property value="varHoldingKey"/>

Using <s:property value='getText("varHoldingKey")"/> is NOT allowed because
of syntax error.

Is there a way to display the key's value?

Thanks.

Re: [struts] Tags and variable attributes

Posted by "lei.java@gmail.com" <le...@gmail.com>.
Thanks Dale for your explanation

On Jan 7, 2008 2:33 PM, Dale Newfield <Da...@newfield.org> wrote:

> lei.java@gmail.com wrote:
> > It works. What's behind it? I even can't believe it.
>
> Before you were using ognl to call getText with a string argument
> "varHoldingKey".  Without those strings you're now calling that same
> method with the evaluated value of the action attribute varHoldingKey.
> (Technically, varHoldingKey is evaluated against the value stack, but
> typically the action is the top item on that stack, so as long as your
> action has that attribute, and nothing higher on the stack does as well,
> the result is the same.)
>
> >> So, have you tried <s:property value='%{getText(varHoldingKey)}'/> ?
>
> -Dale
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [struts] Tags and variable attributes

Posted by Dale Newfield <Da...@Newfield.org>.
lei.java@gmail.com wrote:
> It works. What's behind it? I even can't believe it.

Before you were using ognl to call getText with a string argument 
"varHoldingKey".  Without those strings you're now calling that same 
method with the evaluated value of the action attribute varHoldingKey.
(Technically, varHoldingKey is evaluated against the value stack, but 
typically the action is the top item on that stack, so as long as your 
action has that attribute, and nothing higher on the stack does as well, 
the result is the same.)

>> So, have you tried <s:property value='%{getText(varHoldingKey)}'/> ?

-Dale

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


Re: [struts] Tags and variable attributes

Posted by "lei.java@gmail.com" <le...@gmail.com>.
It works. What's behind it? I even can't believe it.

Thanks so much.

On Jan 7, 2008 12:17 AM, Dale Newfield <Da...@newfield.org> wrote:

> lei.java@gmail.com wrote:
> > If the "varHoldingKey" is a key, it works fine. However, it is not a key
> > itself. It is an action property holding the key.
>
> So, have you tried <s:property value='%{getText(varHoldingKey)}'/> ?
>
> -Dale
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [struts] Tags and variable attributes

Posted by Dale Newfield <Da...@Newfield.org>.
lei.java@gmail.com wrote:
> If the "varHoldingKey" is a key, it works fine. However, it is not a key
> itself. It is an action property holding the key.

So, have you tried <s:property value='%{getText(varHoldingKey)}'/> ?

-Dale

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


Re: [struts] Tags and variable attributes

Posted by "lei.java@gmail.com" <le...@gmail.com>.
Thanks Dave.

I wanted to do it either in the bean class or in the view page but now it
seems I have to deal with that in the action class.
Thanks again.


On Jan 6, 2008 3:42 PM, Dave Newton <ne...@yahoo.com> wrote:

> Get the text in the action.
>
> You should be able to call a method inside getText, though.
>
> --- "lei.java@gmail.com" <le...@gmail.com> wrote:
>
> > Thanks Dave and Dale.
> >
> > If the "varHoldingKey" is a key, it works fine. However, it is not a key
>
> > itself. It is an action property holding the key.
> >
> > Suppose the key is "confirm.title" so varHoldingKey's value is the "
> > confirm.title" string. In the view, <s:property value="varHoldingKey"/>
> > will
> > display "confirm.title".
> >
> > <s:property value='getText("varHoldingKey")'/> doesn't show the value of
> > the
> > key "confirm.title" as it tries to display the value of the key
> > "varHoldingKey" but actually the "varHoldingKey" is not a property's key
> > and
> > it is a variable holding the key.
> >
> > My question is if there is a way to display the key's value in the view
> > page
> > with the variable holding the key but actually not knowing what the key
> is.
> >
> > Many thanks.
> >
> >
> >
> > On Jan 6, 2008 1:43 PM, Dale Newfield < Dale@newfield.org> wrote:
> >
> > > lei.java@gmail.com wrote:
> > > > Using <s:property value='getText("varHoldingKey")"/> is NOT allowed
> > > because
> > > > of syntax error.
> > >
> > > The syntax error is that you have unmatched ''s and "'s.
> > >
> > > -Dale
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > > For additional commands, e-mail: user-help@struts.apache.org
> > >
> > >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [struts] Tags and variable attributes

Posted by Dave Newton <ne...@yahoo.com>.
Get the text in the action.

You should be able to call a method inside getText, though.

--- "lei.java@gmail.com" <le...@gmail.com> wrote:

> Thanks Dave and Dale.
> 
> If the "varHoldingKey" is a key, it works fine. However, it is not a key
> itself. It is an action property holding the key.
> 
> Suppose the key is "confirm.title" so varHoldingKey's value is the "
> confirm.title" string. In the view, <s:property value="varHoldingKey"/>
> will
> display "confirm.title".
> 
> <s:property value='getText("varHoldingKey")'/> doesn't show the value of
> the
> key "confirm.title" as it tries to display the value of the key
> "varHoldingKey" but actually the "varHoldingKey" is not a property's key
> and
> it is a variable holding the key.
> 
> My question is if there is a way to display the key's value in the view
> page
> with the variable holding the key but actually not knowing what the key is.
> 
> Many thanks.
> 
> 
> 
> On Jan 6, 2008 1:43 PM, Dale Newfield <Da...@newfield.org> wrote:
> 
> > lei.java@gmail.com wrote:
> > > Using <s:property value='getText("varHoldingKey")"/> is NOT allowed
> > because
> > > of syntax error.
> >
> > The syntax error is that you have unmatched ''s and "'s.
> >
> > -Dale
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> 


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


Re: [struts] Tags and variable attributes

Posted by "lei.java@gmail.com" <le...@gmail.com>.
Thanks Dave and Dale.

If the "varHoldingKey" is a key, it works fine. However, it is not a key
itself. It is an action property holding the key.

Suppose the key is "confirm.title" so varHoldingKey's value is the "
confirm.title" string. In the view, <s:property value="varHoldingKey"/> will
display "confirm.title".

<s:property value='getText("varHoldingKey")'/> doesn't show the value of the
key "confirm.title" as it tries to display the value of the key
"varHoldingKey" but actually the "varHoldingKey" is not a property's key and
it is a variable holding the key.

My question is if there is a way to display the key's value in the view page
with the variable holding the key but actually not knowing what the key is.

Many thanks.



On Jan 6, 2008 1:43 PM, Dale Newfield <Da...@newfield.org> wrote:

> lei.java@gmail.com wrote:
> > Using <s:property value='getText("varHoldingKey")"/> is NOT allowed
> because
> > of syntax error.
>
> The syntax error is that you have unmatched ''s and "'s.
>
> -Dale
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [struts] Tags and variable attributes

Posted by Dale Newfield <Da...@Newfield.org>.
lei.java@gmail.com wrote:
> Using <s:property value='getText("varHoldingKey")"/> is NOT allowed because
> of syntax error.

The syntax error is that you have unmatched ''s and "'s.

-Dale

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


Re: Tags and variable attributes

Posted by Dave Newton <ne...@yahoo.com>.
--- "lei.java@gmail.com" <le...@gmail.com> wrote:
> Using <s:property value='getText("varHoldingKey")"/> is NOT allowed because
> of syntax error.

Is that a typo?

I use getText(...) inside <s:property.../> tags fairly frequently w/o issue.

d.


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