You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by marcus dickerhof <ma...@googlemail.com> on 2007/10/01 16:38:11 UTC

Newbie Question Loading localization Resources from Database

Hi,
could you please help me with the following problem:
I use wicket 1.3.0 beta 3 + java 1.4.2 + tomcat 5.5

I wrote a small page that has a <wicket:message key="helloWorld">

when running tomcat I get:
[Localizer] Tried to retrieve a localized string for a component that has
not yet been added to the page. This can sometimes lead to an invalid or no
localized resource returned. Make sure you are not calling
Component#getString() inside your Component's constructor. Offending
component: [Page class = com.ppa.ubs.lbs.pages.Login, id = 0, version = 7,
ajax = 0]

Then I wrote a DatabaseResourceLoader implementing IStringResourceLoader

public String loadStringResource(Class clazz, String key, Locale locale,
String style) {

//funny effect locale.getLanguage() --> Nullpointer Exception
//I have to call locale.clone().getLanguage(). Is that normal? ?????
... do some db lookup
}



Then I added some changeLocale-Links to the page constructor:

add( new Link("localeEN"){
public void onClick() {
getSession().setLocale(new Locale("en", "EN"));
}
});
add( new Link("localeDE"){
public void onClick() {
getSession().setLocale(new Locale("de", "DE"));
}
});


The problem: When I change the locale through the Links, the message still
remains the same. The locale passed to the DatabaseResourceLoader always is
DE (german).
Question: Can it be, that the Session-Locale is not used, because of the
Localizer-Problem? Which locale is used instead?
Is there a better way to get database-resource-strings?

Thanks for your help in advance

Best regards
Marcus

Re: Newbie Question Loading localization Resources from Database

Posted by marcus dickerhof <ma...@googlemail.com>.
Hi Eleco,
I' sorry somehow the problem with the locale being null is solved. I cannot
reconstruct it.
But the problem with the locale passed to
IStringResourceLoader.loadStringResource(..) being DE remains.

I have the feeling that the SessionLocale is not used. I verified this by
putting a label on the page (contents: getLocale().toString().) and doing a
System.out.println("locale:" + locale.toString()); in the loadStringResouce
method.

I need to load the String resources from a database because the customer
wants to make changes to the text without re-deploying the war-file.
Do you need more infos? Thank you very much. I think wicket is a great
product, so far.

Best regards from germany
Marcus



2007/10/2, Eelco Hillenius <ee...@gmail.com>:
>
> > //funny effect locale.getLanguage() --> Nullpointer Exception
> > //I have to call locale.clone().getLanguage(). Is that normal? ?????
>
> Could you give us the full stack trace please?
>
> Eelco
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Newbie Question Loading localization Resources from Database

Posted by Eelco Hillenius <ee...@gmail.com>.
> //funny effect locale.getLanguage() --> Nullpointer Exception
> //I have to call locale.clone().getLanguage(). Is that normal? ?????

Could you give us the full stack trace please?

Eelco

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


Re: Newbie Question Loading localization Resources from Database

Posted by Frank Bille <fr...@apache.org>.
On 10/2/07, marcus dickerhof <ma...@googlemail.com> wrote:
>
> Hi I just found out that this issue should be fixed in wicket 1.3.0 beta 4
> (wicket-issue 936). Where can I get that?


beta4 is not released yet. If nothing comes in the way I will release beta4
this weekend.


Frank

Re: Newbie Question Loading localization Resources from Database

Posted by marcus dickerhof <ma...@googlemail.com>.
Hi I just found out that this issue should be fixed in wicket 1.3.0 beta 4
(wicket-issue 936). Where can I get that? Which is the current release, best
suited for a production environment?
Thanks!

Marcus



2007/10/2, marcus dickerhof <ma...@googlemail.com>:
>
> So,
> I looked at the sources of Localizer,
> for "Tried to retrieve a localized string for a component that has not yet
> been added to the page. " which is the warning i get.
>
> In this case the Localizer calls loader.loadStringResource(component,
> key); without passing a locale. That's why I always get the german text :-)
> Sorry!
> But now how can I avoid this "component that has not yet been added to the
> page." problem?
> When I use a wicket:message tag, do I also have to add that message to the
> page-tree in my Java class manually?
>
> Thanks
> Marcus
>
>
>
>
> 2007/10/2, marcus dickerhof < makkan77@googlemail.com>:
> >
> > Hi Cristina,
> > thanks for your reply.
> > The problem is, that the session locale is changed, but somehow
> > there seems to be another locale present which is then passed to the
> > IStringResourceLoader.loadStringResource implementation.
> > Have you got any ideas?
> >
> > Thanks a lot
> > Marcus
> >
> > 2007/10/2, Cristina < cristina@acm.org>:
> > >
> > >
> > > Hi Marcus,
> > >
> > >
> > > marcus dickerhof wrote:
> > > >
> > > > [...]
> > > > Question: Can it be, that the Session-Locale is not used, because of
> > > the
> > > > Localizer-Problem? Which locale is used instead?
> > > >
> > >
> > > If you're setting the Locale in your Session (probably a class that
> > > extends
> > > WebSession) and then getting the Locale through the Session, the
> > > warning
> > > about the Localizer doesn't mean, as far as I know, that the Session
> > > Locale
> > > isn't being used. Otherwise, the default Locale, which is defined by
> > > your
> > > browser settings, will be used.
> > >
> > >
> > > marcus dickerhof wrote:
> > > >
> > > > Is there a better way to get database-resource-strings?
> > > >
> > >
> > > I believe .properties files are a better way to get localized
> > > strings... Is
> > > there any reason why you can't/shouldn't use them?
> > >
> > > Hope this helps,
> > >
> > > Cristina
> > >
> > > --
> > > View this message in context: http://www.nabble.com/Newbie-Question-Loading-localization-Resources-from-Database-tf4548742.html#a12990188
> > >
> > > 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: Newbie Question Loading localization Resources from Database

Posted by marcus dickerhof <ma...@googlemail.com>.
So,
I looked at the sources of Localizer,
for "Tried to retrieve a localized string for a component that has not yet
been added to the page. " which is the warning i get.

In this case the Localizer calls loader.loadStringResource(component, key);
without passing a locale. That's why I always get the german text :-) Sorry!
But now how can I avoid this "component that has not yet been added to the
page." problem?
When I use a wicket:message tag, do I also have to add that message to the
page-tree in my Java class manually?

Thanks
Marcus




2007/10/2, marcus dickerhof <ma...@googlemail.com>:
>
> Hi Cristina,
> thanks for your reply.
> The problem is, that the session locale is changed, but somehow
> there seems to be another locale present which is then passed to the
> IStringResourceLoader.loadStringResource implementation.
> Have you got any ideas?
>
> Thanks a lot
> Marcus
>
> 2007/10/2, Cristina <cr...@acm.org>:
> >
> >
> > Hi Marcus,
> >
> >
> > marcus dickerhof wrote:
> > >
> > > [...]
> > > Question: Can it be, that the Session-Locale is not used, because of
> > the
> > > Localizer-Problem? Which locale is used instead?
> > >
> >
> > If you're setting the Locale in your Session (probably a class that
> > extends
> > WebSession) and then getting the Locale through the Session, the warning
> > about the Localizer doesn't mean, as far as I know, that the Session
> > Locale
> > isn't being used. Otherwise, the default Locale, which is defined by
> > your
> > browser settings, will be used.
> >
> >
> > marcus dickerhof wrote:
> > >
> > > Is there a better way to get database-resource-strings?
> > >
> >
> > I believe .properties files are a better way to get localized strings...
> > Is
> > there any reason why you can't/shouldn't use them?
> >
> > Hope this helps,
> >
> > Cristina
> >
> > --
> > View this message in context: http://www.nabble.com/Newbie-Question-Loading-localization-Resources-from-Database-tf4548742.html#a12990188
> >
> > 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: Newbie Question Loading localization Resources from Database

Posted by marcus dickerhof <ma...@googlemail.com>.
Hi Cristina,
thanks for your reply.
The problem is, that the session locale is changed, but somehow
there seems to be another locale present which is then passed to the
IStringResourceLoader.loadStringResource implementation.
Have you got any ideas?

Thanks a lot
Marcus

2007/10/2, Cristina <cr...@acm.org>:
>
>
> Hi Marcus,
>
>
> marcus dickerhof wrote:
> >
> > [...]
> > Question: Can it be, that the Session-Locale is not used, because of the
> > Localizer-Problem? Which locale is used instead?
> >
>
> If you're setting the Locale in your Session (probably a class that
> extends
> WebSession) and then getting the Locale through the Session, the warning
> about the Localizer doesn't mean, as far as I know, that the Session
> Locale
> isn't being used. Otherwise, the default Locale, which is defined by your
> browser settings, will be used.
>
>
> marcus dickerhof wrote:
> >
> > Is there a better way to get database-resource-strings?
> >
>
> I believe .properties files are a better way to get localized strings...
> Is
> there any reason why you can't/shouldn't use them?
>
> Hope this helps,
>
> Cristina
>
> --
> View this message in context:
> http://www.nabble.com/Newbie-Question-Loading-localization-Resources-from-Database-tf4548742.html#a12990188
> 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: Newbie Question Loading localization Resources from Database

Posted by Cristina <cr...@acm.org>.
Hi Marcus,


marcus dickerhof wrote:
> 
> [...]
> Question: Can it be, that the Session-Locale is not used, because of the
> Localizer-Problem? Which locale is used instead?
> 

If you're setting the Locale in your Session (probably a class that extends
WebSession) and then getting the Locale through the Session, the warning
about the Localizer doesn't mean, as far as I know, that the Session Locale
isn't being used. Otherwise, the default Locale, which is defined by your
browser settings, will be used.


marcus dickerhof wrote:
> 
> Is there a better way to get database-resource-strings?
> 

I believe .properties files are a better way to get localized strings... Is
there any reason why you can't/shouldn't use them?

Hope this helps,

Cristina

-- 
View this message in context: http://www.nabble.com/Newbie-Question-Loading-localization-Resources-from-Database-tf4548742.html#a12990188
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