You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by lesterburlap <be...@emc.com> on 2008/08/19 00:06:49 UTC
ResourceModel vs. getLocalizer
Hi!
Which is generally the preferred / least expensive way to get a resource
string?
new ResourceModel("my.resource.key").getObject().toString();
or
getLocalizer().getString("my.resource.key", MyComponent.this);
I've been using getLocalizer almost everywhere, and only using ResourceModel
when I'm trying to get a property string during Component construction (to
avoid those getLocalizer warnings). But I'm not really sure if my reasoning
is good...
Thanks for any input.
LBB
--
View this message in context: http://www.nabble.com/ResourceModel-vs.-getLocalizer-tp19040992p19040992.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: ResourceModel vs. getLocalizer
Posted by lesterburlap <be...@emc.com>.
> you can however safely construct a ResourceModel
> (but not call getObject on it).
So, doing ResourceModel("key").getObject().getString() is really kind of
silly and defeats the whole purpose of the ResourceModel?
LBB
--
View this message in context: http://www.nabble.com/ResourceModel-vs.-getLocalizer-tp19040992p19051586.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: ResourceModel vs. getLocalizer
Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Tue, 19 Aug 2008, Erik van Oosten wrote:
> There is a big difference, the model variant will evaluate during the
> render phase. You can not use localization in the constructor of your
Well, this
new ResourceModel("my.resource.key").getObject().toString();
will of course evaluate right away (and thus cannot be used
in a constructor), but as lesterburlap also came to think,
this is a really weird use of ResourceModel :) What you say
here
> component, you can however safely construct a ResourceModel (but not
> call getObject on it).
would be the "normal" way.
Best wishes,
Timo
--
Timo Rantalaiho
Reaktor Innovations Oy <URL: http://www.ri.fi/ >
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: ResourceModel vs. getLocalizer
Posted by Erik van Oosten <e....@grons.nl>.
There is a big difference, the model variant will evaluate during the
render phase. You can not use localization in the constructor of your
component, you can however safely construct a ResourceModel (but not
call getObject on it).
In general, I would use localizer when you need direct access to a
message from code. This should be rare though, most message can be
placed with the <wicket:message> element.
Regards,
Erik.
Timo Rantalaiho wrote:
> On Mon, 18 Aug 2008, lesterburlap wrote:
>
>> new ResourceModel("my.resource.key").getObject().toString();
>> or
>> getLocalizer().getString("my.resource.key", MyComponent.this);
>>
>
> Isn't the latter same as
>
> Component.getString("my.resource.key");
>
> ?
>
> And ResourceModel can typically be used directly as the
> model of the Label displaying the String
>
> add(new Label("foo", new ResourceModel("my.resource.key")));
>
>
>> I've been using getLocalizer almost everywhere, and only using ResourceModel
>> when I'm trying to get a property string during Component construction (to
>> avoid those getLocalizer warnings). But I'm not really sure if my reasoning
>> is good...
>>
>
> I wouldn't think that there is any difference. If you are
> worried about performance, try profiling the application.
>
> Best wishes,
> Timo
>
--
Erik van Oosten
http://day-to-day-stuff.blogspot.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: ResourceModel vs. getLocalizer
Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Mon, 18 Aug 2008, lesterburlap wrote:
> new ResourceModel("my.resource.key").getObject().toString();
> or
> getLocalizer().getString("my.resource.key", MyComponent.this);
Isn't the latter same as
Component.getString("my.resource.key");
?
And ResourceModel can typically be used directly as the
model of the Label displaying the String
add(new Label("foo", new ResourceModel("my.resource.key")));
> I've been using getLocalizer almost everywhere, and only using ResourceModel
> when I'm trying to get a property string during Component construction (to
> avoid those getLocalizer warnings). But I'm not really sure if my reasoning
> is good...
I wouldn't think that there is any difference. If you are
worried about performance, try profiling the application.
Best wishes,
Timo
--
Timo Rantalaiho
Reaktor Innovations Oy <URL: http://www.ri.fi/ >
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org