You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Zilvinas Vilutis <ci...@gmail.com> on 2010/04/20 00:36:25 UTC

String Resource Loading from DB

Has anybody had implemented smth like that ( @see topic ) and / or had
any practice with this?

I'm looking for a resource loading solution for quite a big web-site
project which would be localized to many languages and may need to
require update at runtime using some administration panel.

Or is that so easy as implementing the IStringResourceLoader ?


Looking forward for any opinion on this.

Thank you

Žilvinas Vilutis

Mobile:   (+370) 652 38353
E-mail:   cikasfm@gmail.com

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


Re: String Resource Loading from DB

Posted by Josh Glassman <jo...@gmail.com>.
Ah, right... we got around that by not using the class (partly so we could
use the same resource strings across different classes).  The only other
thing I can suggest is to use more unique keys for anonymous classes, though
that is clearly not ideal.  Maybe someone else knows a better solution.

On Thu, Apr 22, 2010 at 3:27 AM, Zilvinas Vilutis <ci...@gmail.com> wrote:

> the combination of class, key, locale, style must be unique, so if I
> have the same keys ( while locale and style is not changing ) - the
> classname must be unique. So I cannot use this in anonymous classes,
> as it does not resolve, e.g. page class name
>
>
> Žilvinas Vilutis
>
> Mobile:   (+370) 652 38353
> E-mail:   cikasfm@gmail.com
>
>
>
> On Wed, Apr 21, 2010 at 1:46 PM, Josh Glassman <jo...@gmail.com> wrote:
> > Not sure what you mean about implementing a unique class... any class
> which
> > inherits from Component can call getString(String key), which will call
> your
> > custom IStringResourceLoader.  Additionally, you can set the locale on
> any
> > MarkupContainer or the Session, and Components will use their parent's
> > locale falling back to the Session's.
> >
> > You can also use the wicket:message tag directly in your markup, which
> uses
> > whatever locale it's associated class uses.
> >
> > What we do is set the locale on the Session, and use that and a resource
> key
> > to pull the string from the database.  We use DB caching, and turn off
> the
> > built-in resource string caching that wicket does (see below, goes in
> > WebApplication.init()).
> >
> > getResourceSettings().setLocalizer(new Localizer() {
> >   @Override
> >   protected void putIntoCache(String cacheKey, String string) {
> >      // Do nothing... no caching desired, since our DB layer caches
> >   }
> > });
> >
> >
> >
> > On Tue, Apr 20, 2010 at 1:53 PM, Zilvinas Vilutis <ci...@gmail.com>
> wrote:
> >
> >> Yes,
> >>
> >> That seems to work. Although each component which needs to be
> >> localized needs to implement a unique class, 'cause in many cases the
> >> Component class is "WebMarkupContainer" ( if we use components in list
> >> & etc ).
> >>
> >> Does anyone have practice on using any performance experience on that?
> >>
> >> Do you use DB caching or method caching?
> >>
> >>
> >> Žilvinas Vilutis
> >>
> >> Mobile:   (+370) 652 38353
> >> E-mail:   cikasfm@gmail.com
> >>
> >>
> >>
> >> On Tue, Apr 20, 2010 at 7:40 AM, Josh Glassman <jo...@gmail.com>
> wrote:
> >> > Yup, you have the right idea.
> >> >
> >> > Something like...
> >> >    public class DatabaseStringResourceLoader implements
> >> > IStringResourceLoader {...}
> >> >
> >> > And then in your WebApplication.init()...
> >> >    getResourceSettings().addStringResourceLoader(new
> >> > DatabaseStringResourceLoader());
> >> >
> >> > Cheers,
> >> > Josh
> >> >
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: String Resource Loading from DB

Posted by Zilvinas Vilutis <ci...@gmail.com>.
the combination of class, key, locale, style must be unique, so if I
have the same keys ( while locale and style is not changing ) - the
classname must be unique. So I cannot use this in anonymous classes,
as it does not resolve, e.g. page class name


Žilvinas Vilutis

Mobile:   (+370) 652 38353
E-mail:   cikasfm@gmail.com



On Wed, Apr 21, 2010 at 1:46 PM, Josh Glassman <jo...@gmail.com> wrote:
> Not sure what you mean about implementing a unique class... any class which
> inherits from Component can call getString(String key), which will call your
> custom IStringResourceLoader.  Additionally, you can set the locale on any
> MarkupContainer or the Session, and Components will use their parent's
> locale falling back to the Session's.
>
> You can also use the wicket:message tag directly in your markup, which uses
> whatever locale it's associated class uses.
>
> What we do is set the locale on the Session, and use that and a resource key
> to pull the string from the database.  We use DB caching, and turn off the
> built-in resource string caching that wicket does (see below, goes in
> WebApplication.init()).
>
> getResourceSettings().setLocalizer(new Localizer() {
>   @Override
>   protected void putIntoCache(String cacheKey, String string) {
>      // Do nothing... no caching desired, since our DB layer caches
>   }
> });
>
>
>
> On Tue, Apr 20, 2010 at 1:53 PM, Zilvinas Vilutis <ci...@gmail.com> wrote:
>
>> Yes,
>>
>> That seems to work. Although each component which needs to be
>> localized needs to implement a unique class, 'cause in many cases the
>> Component class is "WebMarkupContainer" ( if we use components in list
>> & etc ).
>>
>> Does anyone have practice on using any performance experience on that?
>>
>> Do you use DB caching or method caching?
>>
>>
>> Žilvinas Vilutis
>>
>> Mobile:   (+370) 652 38353
>> E-mail:   cikasfm@gmail.com
>>
>>
>>
>> On Tue, Apr 20, 2010 at 7:40 AM, Josh Glassman <jo...@gmail.com> wrote:
>> > Yup, you have the right idea.
>> >
>> > Something like...
>> >    public class DatabaseStringResourceLoader implements
>> > IStringResourceLoader {...}
>> >
>> > And then in your WebApplication.init()...
>> >    getResourceSettings().addStringResourceLoader(new
>> > DatabaseStringResourceLoader());
>> >
>> > Cheers,
>> > Josh
>> >
>>
>

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


Re: String Resource Loading from DB

Posted by Josh Glassman <jo...@gmail.com>.
Not sure what you mean about implementing a unique class... any class which
inherits from Component can call getString(String key), which will call your
custom IStringResourceLoader.  Additionally, you can set the locale on any
MarkupContainer or the Session, and Components will use their parent's
locale falling back to the Session's.

You can also use the wicket:message tag directly in your markup, which uses
whatever locale it's associated class uses.

What we do is set the locale on the Session, and use that and a resource key
to pull the string from the database.  We use DB caching, and turn off the
built-in resource string caching that wicket does (see below, goes in
WebApplication.init()).

getResourceSettings().setLocalizer(new Localizer() {
   @Override
   protected void putIntoCache(String cacheKey, String string) {
      // Do nothing... no caching desired, since our DB layer caches
   }
});



On Tue, Apr 20, 2010 at 1:53 PM, Zilvinas Vilutis <ci...@gmail.com> wrote:

> Yes,
>
> That seems to work. Although each component which needs to be
> localized needs to implement a unique class, 'cause in many cases the
> Component class is "WebMarkupContainer" ( if we use components in list
> & etc ).
>
> Does anyone have practice on using any performance experience on that?
>
> Do you use DB caching or method caching?
>
>
> Žilvinas Vilutis
>
> Mobile:   (+370) 652 38353
> E-mail:   cikasfm@gmail.com
>
>
>
> On Tue, Apr 20, 2010 at 7:40 AM, Josh Glassman <jo...@gmail.com> wrote:
> > Yup, you have the right idea.
> >
> > Something like...
> >    public class DatabaseStringResourceLoader implements
> > IStringResourceLoader {...}
> >
> > And then in your WebApplication.init()...
> >    getResourceSettings().addStringResourceLoader(new
> > DatabaseStringResourceLoader());
> >
> > Cheers,
> > Josh
> >
>

Re: String Resource Loading from DB

Posted by Zilvinas Vilutis <ci...@gmail.com>.
Yes,

That seems to work. Although each component which needs to be
localized needs to implement a unique class, 'cause in many cases the
Component class is "WebMarkupContainer" ( if we use components in list
& etc ).

Does anyone have practice on using any performance experience on that?

Do you use DB caching or method caching?


Žilvinas Vilutis

Mobile:   (+370) 652 38353
E-mail:   cikasfm@gmail.com



On Tue, Apr 20, 2010 at 7:40 AM, Josh Glassman <jo...@gmail.com> wrote:
> Yup, you have the right idea.
>
> Something like...
>    public class DatabaseStringResourceLoader implements
> IStringResourceLoader {...}
>
> And then in your WebApplication.init()...
>    getResourceSettings().addStringResourceLoader(new
> DatabaseStringResourceLoader());
>
> Cheers,
> Josh
>

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


Re: String Resource Loading from DB

Posted by Josh Glassman <jo...@gmail.com>.
Yup, you have the right idea.

Something like...
   public class DatabaseStringResourceLoader implements
IStringResourceLoader {...}

And then in your WebApplication.init()...
   getResourceSettings().addStringResourceLoader(new
DatabaseStringResourceLoader());

Cheers,
Josh