You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ricardo Jorge <rv...@gmail.com> on 2010/03/04 17:42:03 UTC

Passing parameters to

Hello.

I need to access a property the includes a parameter but I cannot find a way
to do it.

I want to list all page names in selectedPages but I also need to specify
the locale (language) the should appear because a page may have many names
in different languages:

This works fine. It's a normal getName():

<ul>
    <s:iterator value="selectedPages" status="row">
        <li>
            <s:property value="name" />
        </li>
    </s:iterator>
</ul>

but I needed to do something like

<ul>
    <s:iterator value="selectedPages" status="row">
        <li>
            <s:property value="name(Locale.US)" />
        </li>
    </s:iterator>
</ul>

Best Regards,
Ricardo

RE: Passing parameters to

Posted by adam pinder <ap...@hotmail.co.uk>.
 

use an alias in the getName call like so

 

<s:property value="getName('US')"/>

 

this will still call getName but pass the string "US" then make the class method getName do the locale related work.

 

you can't pass an object in a property call as far as i know only a primitive/string.

 

i still think you should be looking at this differently and using the i18n interceptor and resource bundles to handle different languages.

 

adam


 
> Date: Thu, 4 Mar 2010 17:13:43 +0000
> Subject: Re: Passing parameters to <s:property>
> From: rvjsapi@gmail.com
> To: user@struts.apache.org
> 
> Thank you for your reply.
> 
> I don't have a getName in my action class if that's what you mean.
> 
> I'm using an iterator so the getName is a method from the class's object
> defined in the iterator's value option. That class also makes available a
> getName(Locale locale).
> 
> Locale is a class (java.util.Locale).
> 
> PS: I've just tried the following but it did not work
> <s:property value="name(@java.util.Locale@US)" />
> 
> Best Regards
> Ricardo
> 
> On Thu, Mar 4, 2010 at 4:51 PM, Lukasz Lenart
> <lu...@googlemail.com>wrote:
> 
> > 2010/3/4 Ricardo Jorge <rv...@gmail.com>:
> > > <s:property value="name(Locale.US)" />
> >
> > Did you define method name(Locale locale) in your class? Or just
> > getName(Locale locale)? For second case use
> > <s:property value="getName(Locale.US)" /> or <s:property
> > value="%{getName(Locale.US)}" />
> >
> >
> > Regards
> > --
> > Łukasz
> > http://www.lenart.org.pl/
> > Kapituła Javarsovia 2010
> > http://javarsovia.pl
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
 		 	   		  
_________________________________________________________________
Got a cool Hotmail story? Tell us now
http://clk.atdmt.com/UKM/go/195013117/direct/01/

Re: Passing parameters to

Posted by Ricardo Jorge <rv...@gmail.com>.
Thank you both for your help. I got this working with your suggestions. :)

I made an experiment with various ways of working this out. Here are the
results. They may be helpful to others looking for the same answer.

1. Doesn't work
            name('Locale.US'): <s:property value="name('Locale.US')" />


2. Doesn't work
            name(Locale.US): <s:property value="name(Locale.US)" />


3. Doesn't work
            getName(Locale.US): <s:property value="getName(Locale.US)" />


4. Works. notice the ' in the parameter
            getName('Locale.US'): <s:property value="getName('Locale.US')"
/>

5. Works. i tried something similar before but I was just using 'name'
instead of 'getName'
            getName(@java.util.Locale@US): <s:property
value="getName(@java.util.Locale@US)" />


6. Doesn't wok. I tried this previously. See nº5
            name(@java.util.Locale@US): <s:property
value="name(@java.util.Locale@US)" />


7. Works but probably only because there is also a getName(String s) where s
is the locale as a string
            name('en_US'): <s:property value="getName('en_US')" />


8. Works but probably only because there is also a getName(String s) where s
is the locale as a string
            name('US'): <s:property value="getName('US')" />



Also, I did not need to use struts.ognl.allowStaticMethodAccess

-------------

>
> i still think you should be looking at this differently and using the i18n
interceptor and resource bundles to handle different
> languages.

@adam: I'm using Liferay and this is a class provided by the Portal to get
the names of the pages in localized format. The getName method (without
parameters) returns XML content with the various languages so I need to get
the right locale using the provided getName(Locale locale).

Perhaps I could create an additional class where I would store the
information I need in an already localized format and handle this in the
Action.

Best Regards,
Ricardo





2010/3/4 adam pinder <ap...@hotmail.co.uk>

>
>
>
> just pass an alias to the locale in the parameter
>
>
>
> <s:property value="getName('US')"/>
>
>
>
> and let the getName class handle the actual locale.
>
>
>
> adam
>
> > Date: Thu, 4 Mar 2010 18:20:19 +0100
> > Subject: Re: Passing parameters to <s:property>
> > From: lukasz.lenart@googlemail.com
> > To: user@struts.apache.org
> >
> > 2010/3/4 Ricardo Jorge <rv...@gmail.com>:
> > > PS: I've just tried the following but it did not work
> > > <s:property value="name(@java.util.Locale@US)" />
> >
> > Take a look on some examples here [1] and try
> > <s:property value="getName(@java.util.Locale@US)" />
> >
> > [1] http://struts.apache.org/2.x/docs/ognl-basics.html
> >
> >
> > Regards
> > --
> > Łukasz
> > http://www.lenart.org.pl/
> > Kapituła Javarsovia 2010
> > http://javarsovia.pl
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
>
> _________________________________________________________________
> Tell us your greatest, weirdest and funniest Hotmail stories
> http://clk.atdmt.com/UKM/go/195013117/direct/01/
>

RE: Passing parameters to

Posted by adam pinder <ap...@hotmail.co.uk>.
 

just pass an alias to the locale in the parameter

 

<s:property value="getName('US')"/>

 

and let the getName class handle the actual locale.

 

adam
 
> Date: Thu, 4 Mar 2010 18:20:19 +0100
> Subject: Re: Passing parameters to <s:property>
> From: lukasz.lenart@googlemail.com
> To: user@struts.apache.org
> 
> 2010/3/4 Ricardo Jorge <rv...@gmail.com>:
> > PS: I've just tried the following but it did not work
> > <s:property value="name(@java.util.Locale@US)" />
> 
> Take a look on some examples here [1] and try
> <s:property value="getName(@java.util.Locale@US)" />
> 
> [1] http://struts.apache.org/2.x/docs/ognl-basics.html
> 
> 
> Regards
> -- 
> Łukasz
> http://www.lenart.org.pl/
> Kapituła Javarsovia 2010
> http://javarsovia.pl
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
 		 	   		  
_________________________________________________________________
Tell us your greatest, weirdest and funniest Hotmail stories
http://clk.atdmt.com/UKM/go/195013117/direct/01/

Re: Passing parameters to

Posted by Lukasz Lenart <lu...@googlemail.com>.
2010/3/4 Ricardo Jorge <rv...@gmail.com>:
> PS: I've just tried the following but it did not work
> <s:property value="name(@java.util.Locale@US)" />

Take a look on some examples here [1] and try
<s:property value="getName(@java.util.Locale@US)" />

[1] http://struts.apache.org/2.x/docs/ognl-basics.html


Regards
-- 
Łukasz
http://www.lenart.org.pl/
Kapituła Javarsovia 2010
http://javarsovia.pl

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


Re: Passing parameters to

Posted by Ricardo Jorge <rv...@gmail.com>.
Thank you for your reply.

I don't have a getName in my action class if that's what you mean.

I'm using an iterator so the getName is a method from the class's object
defined in the iterator's value option. That class also makes available a
getName(Locale locale).

Locale is a class (java.util.Locale).

PS: I've just tried the following but it did not work
<s:property value="name(@java.util.Locale@US)" />

Best Regards
Ricardo

On Thu, Mar 4, 2010 at 4:51 PM, Lukasz Lenart
<lu...@googlemail.com>wrote:

> 2010/3/4 Ricardo Jorge <rv...@gmail.com>:
> >            <s:property value="name(Locale.US)" />
>
> Did you define method name(Locale locale) in your class? Or just
> getName(Locale locale)? For second case use
> <s:property value="getName(Locale.US)" /> or <s:property
> value="%{getName(Locale.US)}" />
>
>
> Regards
> --
> Łukasz
> http://www.lenart.org.pl/
> Kapituła Javarsovia 2010
> http://javarsovia.pl
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Passing parameters to

Posted by Lukasz Lenart <lu...@googlemail.com>.
2010/3/4 Ricardo Jorge <rv...@gmail.com>:
>            <s:property value="name(Locale.US)" />

Did you define method name(Locale locale) in your class? Or just
getName(Locale locale)? For second case use
<s:property value="getName(Locale.US)" /> or <s:property
value="%{getName(Locale.US)}" />


Regards
-- 
Łukasz
http://www.lenart.org.pl/
Kapituła Javarsovia 2010
http://javarsovia.pl

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