You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Eyal Golan <eg...@gmail.com> on 2008/11/18 11:21:36 UTC

Usage of getString with parameters (model?)

Hi,
I have a key in the property file:
Reports.ReportTitle.SuspectedConnectionsUserRes = Suspected User-Resource
Connections by {0} Pattern Report

I want to use getString("Reports.ReportTitle.SuspectedConnectionsUserRes",
SOMETHING);
to get the value with the {0} substituted. I'm not sure how to do this.

Please advise,

thanks


Eyal Golan
egolan74@gmail.com

Visit: http://jvdrums.sourceforge.net/
LinkedIn: http://www.linkedin.com/in/egolan74

P  Save a tree. Please don't print this e-mail unless it's really necessary

Re: Usage of getString with parameters (model?)

Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
Igor wrote something about it in a thread with validators.. But heres my 
cut:

            add(new Label("confirmation.content", new StringResourceModel(
                    "confirmation.content", this, eventModel)));
and in property file:

confirmation.content=You are about to create event '${name}', in city 
'${location.nearestCityName}', see preview of event below, please press 
finish to complete. Notice that tags will be populated when confirmed.

Eyal Golan wrote:
> Hi,
> I have a key in the property file:
> Reports.ReportTitle.SuspectedConnectionsUserRes = Suspected User-Resource
> Connections by {0} Pattern Report
>
> I want to use getString("Reports.ReportTitle.SuspectedConnectionsUserRes",
> SOMETHING);
> to get the value with the {0} substituted. I'm not sure how to do this.
>
> Please advise,
>
> thanks
>
>
> Eyal Golan
> egolan74@gmail.com
>
> Visit: http://jvdrums.sourceforge.net/
> LinkedIn: http://www.linkedin.com/in/egolan74
>
> P  Save a tree. Please don't print this e-mail unless it's really necessary
>
>   

-- 
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Usage of getString with parameters (model?)

Posted by Eyal Golan <eg...@gmail.com>.
Nino, Ernesto,
Thanks.

Ernesto, I actually looked into the code that you showed.
I was a bit confused and that's why I asked.
I think your solution will help me.

Thanks.


Eyal Golan
egolan74@gmail.com

Visit: http://jvdrums.sourceforge.net/
LinkedIn: http://www.linkedin.com/in/egolan74

P  Save a tree. Please don't print this e-mail unless it's really necessary


On Tue, Nov 18, 2008 at 1:00 PM, Ernesto Reinaldo Barreiro <
reiern70@gmail.com> wrote:

> Hi Eyal,
>
> If you open the Component class you will see a method:
>
> public String getString(final String key, final Component component, final
> IModel<?> model,
> final String defaultValue) throws MissingResourceException {
> ....
> }
>
> which finds a localizer...  an Localizer after locating the key calls to :
>
> public String substitutePropertyExpressions(final Component component,
> final
> String string,
> final IModel<?> model)
> {
> if ((string != null) && (model != null))
> {
> return PropertyVariableInterpolator.interpolate(string, model.getObject());
> }
> return string;
> }
>
> if you look into the code of PropertyVariableInterpolator you will see it
> delegates to  PropertyResolver for variable sustitution. So, I would guess
> something like:
>
>
>  getString("Reports.ReportTitle.SuspectedConnectionsUserRes", new
> Model<Object>(new Object[]{"bla"});
>
> will produce:
>
> Suspected User-Resource Connections by bla Pattern Report
>
> You could also use:
>
> 1- Suspected User-Resource
> Connections by {bla} Pattern Report
> 2- A bean class
>
> class MyBean {
>   String bla = "bla";
> }
>
> 3- and getString("Reports.ReportTitle.SuspectedConnectionsUserRes", new
> Model<MyBean>(new MyBean());
>
> with the same result. Don't be afraid of looking into Wicket''s source
> code;-)
>
> A quick search in google also shows me the following link
>
>
> http://day-to-day-stuff.blogspot.com/2008/05/wicket-internationalization.html
>
> Best,
>
> Ernesto
>
> On Tue, Nov 18, 2008 at 11:21 AM, Eyal Golan <eg...@gmail.com> wrote:
>
> > Hi,
> > I have a key in the property file:
> > Reports.ReportTitle.SuspectedConnectionsUserRes = Suspected User-Resource
> > Connections by {0} Pattern Report
> >
> > I want to use
> getString("Reports.ReportTitle.SuspectedConnectionsUserRes",
> > SOMETHING);
> > to get the value with the {0} substituted. I'm not sure how to do this.
> >
> > Please advise,
> >
> > thanks
> >
> >
> > Eyal Golan
> > egolan74@gmail.com
> >
> > Visit: http://jvdrums.sourceforge.net/
> > LinkedIn: http://www.linkedin.com/in/egolan74
> >
> > P  Save a tree. Please don't print this e-mail unless it's really
> necessary
> >
>

Re: Usage of getString with parameters (model?)

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
Good you found that you needed on your own ( :-) ) and additionally now
you know why it  works as it does! My point is: sometimes there is no
better documentation that the source code  itself: documentation could
be out-dated but the code will never be...

Best,

Ernesto

Eyal Golan wrote:
> A small addition, if anyone encounters this situation.
> After trying the new Model[]{"bla"}, it still didn't work for me.
> Looking at the code (Ernesto ;) ), I saw in
> PropertyVariableInterpolator.interpolate(...) that it is looking for a "${"
> mark.
> So in my properties file I had to change to be:
> Reports.ReportTitle.SuspectedConnectionsUserRes = Suspected User-Resource
> Connections by ${0} Pattern Report
>
> (The $ was missing before).
>
>
> Eyal Golan
> egolan74@gmail.com
>
> Visit: http://jvdrums.sourceforge.net/
> LinkedIn: http://www.linkedin.com/in/egolan74
>
> P  Save a tree. Please don't print this e-mail unless it's really necessary
>
>
> On Tue, Nov 18, 2008 at 1:00 PM, Ernesto Reinaldo Barreiro <
> reiern70@gmail.com> wrote:
>
>   
>> Hi Eyal,
>>
>> If you open the Component class you will see a method:
>>
>> public String getString(final String key, final Component component, final
>> IModel<?> model,
>> final String defaultValue) throws MissingResourceException {
>> ....
>> }
>>
>> which finds a localizer...  an Localizer after locating the key calls to :
>>
>> public String substitutePropertyExpressions(final Component component,
>> final
>> String string,
>> final IModel<?> model)
>> {
>> if ((string != null) && (model != null))
>> {
>> return PropertyVariableInterpolator.interpolate(string, model.getObject());
>> }
>> return string;
>> }
>>
>> if you look into the code of PropertyVariableInterpolator you will see it
>> delegates to  PropertyResolver for variable sustitution. So, I would guess
>> something like:
>>
>>
>>  getString("Reports.ReportTitle.SuspectedConnectionsUserRes", new
>> Model<Object>(new Object[]{"bla"});
>>
>> will produce:
>>
>> Suspected User-Resource Connections by bla Pattern Report
>>
>> You could also use:
>>
>> 1- Suspected User-Resource
>> Connections by {bla} Pattern Report
>> 2- A bean class
>>
>> class MyBean {
>>   String bla = "bla";
>> }
>>
>> 3- and getString("Reports.ReportTitle.SuspectedConnectionsUserRes", new
>> Model<MyBean>(new MyBean());
>>
>> with the same result. Don't be afraid of looking into Wicket''s source
>> code;-)
>>
>> A quick search in google also shows me the following link
>>
>>
>> http://day-to-day-stuff.blogspot.com/2008/05/wicket-internationalization.html
>>
>> Best,
>>
>> Ernesto
>>
>> On Tue, Nov 18, 2008 at 11:21 AM, Eyal Golan <eg...@gmail.com> wrote:
>>
>>     
>>> Hi,
>>> I have a key in the property file:
>>> Reports.ReportTitle.SuspectedConnectionsUserRes = Suspected User-Resource
>>> Connections by {0} Pattern Report
>>>
>>> I want to use
>>>       
>> getString("Reports.ReportTitle.SuspectedConnectionsUserRes",
>>     
>>> SOMETHING);
>>> to get the value with the {0} substituted. I'm not sure how to do this.
>>>
>>> Please advise,
>>>
>>> thanks
>>>
>>>
>>> Eyal Golan
>>> egolan74@gmail.com
>>>
>>> Visit: http://jvdrums.sourceforge.net/
>>> LinkedIn: http://www.linkedin.com/in/egolan74
>>>
>>> P  Save a tree. Please don't print this e-mail unless it's really
>>>       
>> necessary
>>     
>
>   


Re: Usage of getString with parameters (model?)

Posted by Eyal Golan <eg...@gmail.com>.
A small addition, if anyone encounters this situation.
After trying the new Model[]{"bla"}, it still didn't work for me.
Looking at the code (Ernesto ;) ), I saw in
PropertyVariableInterpolator.interpolate(...) that it is looking for a "${"
mark.
So in my properties file I had to change to be:
Reports.ReportTitle.SuspectedConnectionsUserRes = Suspected User-Resource
Connections by ${0} Pattern Report

(The $ was missing before).


Eyal Golan
egolan74@gmail.com

Visit: http://jvdrums.sourceforge.net/
LinkedIn: http://www.linkedin.com/in/egolan74

P  Save a tree. Please don't print this e-mail unless it's really necessary


On Tue, Nov 18, 2008 at 1:00 PM, Ernesto Reinaldo Barreiro <
reiern70@gmail.com> wrote:

> Hi Eyal,
>
> If you open the Component class you will see a method:
>
> public String getString(final String key, final Component component, final
> IModel<?> model,
> final String defaultValue) throws MissingResourceException {
> ....
> }
>
> which finds a localizer...  an Localizer after locating the key calls to :
>
> public String substitutePropertyExpressions(final Component component,
> final
> String string,
> final IModel<?> model)
> {
> if ((string != null) && (model != null))
> {
> return PropertyVariableInterpolator.interpolate(string, model.getObject());
> }
> return string;
> }
>
> if you look into the code of PropertyVariableInterpolator you will see it
> delegates to  PropertyResolver for variable sustitution. So, I would guess
> something like:
>
>
>  getString("Reports.ReportTitle.SuspectedConnectionsUserRes", new
> Model<Object>(new Object[]{"bla"});
>
> will produce:
>
> Suspected User-Resource Connections by bla Pattern Report
>
> You could also use:
>
> 1- Suspected User-Resource
> Connections by {bla} Pattern Report
> 2- A bean class
>
> class MyBean {
>   String bla = "bla";
> }
>
> 3- and getString("Reports.ReportTitle.SuspectedConnectionsUserRes", new
> Model<MyBean>(new MyBean());
>
> with the same result. Don't be afraid of looking into Wicket''s source
> code;-)
>
> A quick search in google also shows me the following link
>
>
> http://day-to-day-stuff.blogspot.com/2008/05/wicket-internationalization.html
>
> Best,
>
> Ernesto
>
> On Tue, Nov 18, 2008 at 11:21 AM, Eyal Golan <eg...@gmail.com> wrote:
>
> > Hi,
> > I have a key in the property file:
> > Reports.ReportTitle.SuspectedConnectionsUserRes = Suspected User-Resource
> > Connections by {0} Pattern Report
> >
> > I want to use
> getString("Reports.ReportTitle.SuspectedConnectionsUserRes",
> > SOMETHING);
> > to get the value with the {0} substituted. I'm not sure how to do this.
> >
> > Please advise,
> >
> > thanks
> >
> >
> > Eyal Golan
> > egolan74@gmail.com
> >
> > Visit: http://jvdrums.sourceforge.net/
> > LinkedIn: http://www.linkedin.com/in/egolan74
> >
> > P  Save a tree. Please don't print this e-mail unless it's really
> necessary
> >
>

Re: Usage of getString with parameters (model?)

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
Hi Eyal,

If you open the Component class you will see a method:

public String getString(final String key, final Component component, final
IModel<?> model,
final String defaultValue) throws MissingResourceException {
....
}

which finds a localizer...  an Localizer after locating the key calls to :

public String substitutePropertyExpressions(final Component component, final
String string,
final IModel<?> model)
{
if ((string != null) && (model != null))
{
return PropertyVariableInterpolator.interpolate(string, model.getObject());
}
return string;
}

if you look into the code of PropertyVariableInterpolator you will see it
delegates to  PropertyResolver for variable sustitution. So, I would guess
something like:


 getString("Reports.ReportTitle.SuspectedConnectionsUserRes", new
Model<Object>(new Object[]{"bla"});

will produce:

Suspected User-Resource Connections by bla Pattern Report

You could also use:

1- Suspected User-Resource
Connections by {bla} Pattern Report
2- A bean class

class MyBean {
   String bla = "bla";
}

3- and getString("Reports.ReportTitle.SuspectedConnectionsUserRes", new
Model<MyBean>(new MyBean());

with the same result. Don't be afraid of looking into Wicket''s source
code;-)

A quick search in google also shows me the following link

http://day-to-day-stuff.blogspot.com/2008/05/wicket-internationalization.html

Best,

Ernesto

On Tue, Nov 18, 2008 at 11:21 AM, Eyal Golan <eg...@gmail.com> wrote:

> Hi,
> I have a key in the property file:
> Reports.ReportTitle.SuspectedConnectionsUserRes = Suspected User-Resource
> Connections by {0} Pattern Report
>
> I want to use getString("Reports.ReportTitle.SuspectedConnectionsUserRes",
> SOMETHING);
> to get the value with the {0} substituted. I'm not sure how to do this.
>
> Please advise,
>
> thanks
>
>
> Eyal Golan
> egolan74@gmail.com
>
> Visit: http://jvdrums.sourceforge.net/
> LinkedIn: http://www.linkedin.com/in/egolan74
>
> P  Save a tree. Please don't print this e-mail unless it's really necessary
>