You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Marieke Vandamme <ma...@tvh.be> on 2007/09/05 14:23:47 UTC

write translated messages in renderhead

Hello, 

With new 1.3beta3 release I changed all the entries from StringResourceModel
to ResourceModel to avoid the warning 'Tried to retrieve a localized string
for a component that has not yet been added to the page.' (I still get this
warning when using <wicket:message key=""/> tag.. but I guess that's a bug.)

But now my real problem : 
I'm using the renderHead from IHeaderContributor to print some translated
text in javascript. 

public void renderHead(IHeaderResponse hr) {
    String js += "var myMsg = '" + JavascriptUtils.escapeQuotes(new
ResourceModel("MY_MSG", null) + "") + "';";
    hr.renderJavascript(js, null);
}

But now the result on my html-page is :

var myMsg = 'Model:classname=[org.apache.wicket.model.ResourceModel]';

instead I want my translated "MY_MSG".
Thanks for your help !
-- 
View this message in context: http://www.nabble.com/write-translated-messages-in-renderhead-tf4383719.html#a12496870
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: write translated messages in renderhead

Posted by Johan Compagner <jc...@gmail.com>.
On 9/5/07, Marieke Vandamme <ma...@tvh.be> wrote:
>
>
> new ResourceModel("MY_MSG", null).getObject() gave me nullpointer.



hmm thats because ResourceModel is meant to be wrapped (its an
AsignableModel)
but it should also work without the component:

    return Application.get
().getResourceSettings().getLocalizer().getString(resourceKey,
                (Component)null, defaultValue);

that call with a null component shouldnt give you a nullpointer thats
strange

johan

Re: write translated messages in renderhead

Posted by Marieke Vandamme <ma...@tvh.be>.
getString("key") works perfect for me.. I didn't know something like that
existed.
new ResourceModel("MY_MSG", null).getObject() gave me nullpointer.
Thanks a lot !


Matej Knopp-2 wrote:
> 
> It's easier to just call getString("key") instead of using
> ResourceModel in this case.
> 
> -Matej
> 
> On 9/5/07, Johan Compagner <jc...@gmail.com> wrote:
>> String js += "var myMsg = '" + JavascriptUtils.escapeQuotes(new
>> ResourceModel("MY_MSG", null) + "") + "';";
>>
>> that looks a bit wrong, try something like this
>>
>> String js += "var myMsg = '" + JavascriptUtils.escapeQuotes(new
>> ResourceModel("MY_MSG", null).getObject() + "") + "';";
>>
>> On 9/5/07, Marieke Vandamme <ma...@tvh.be> wrote:
>> >
>> >
>> > Hello,
>> >
>> > With new 1.3beta3 release I changed all the entries from
>> > StringResourceModel
>> > to ResourceModel to avoid the warning 'Tried to retrieve a localized
>> > string
>> > for a component that has not yet been added to the page.' (I still get
>> > this
>> > warning when using <wicket:message key=""/> tag.. but I guess that's a
>> > bug.)
>> >
>> > But now my real problem :
>> > I'm using the renderHead from IHeaderContributor to print some
>> translated
>> > text in javascript.
>> >
>> > public void renderHead(IHeaderResponse hr) {
>> >     String js += "var myMsg = '" + JavascriptUtils.escapeQuotes(new
>> > ResourceModel("MY_MSG", null) + "") + "';";
>> >     hr.renderJavascript(js, null);
>> > }
>> >
>> > But now the result on my html-page is :
>> >
>> > var myMsg = 'Model:classname=[org.apache.wicket.model.ResourceModel]';
>> >
>> > instead I want my translated "MY_MSG".
>> > Thanks for your help !
>> > --
>> > View this message in context:
>> >
>> http://www.nabble.com/write-translated-messages-in-renderhead-tf4383719.html#a12496870
>> > 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
>> >
>> >
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/write-translated-messages-in-renderhead-tf4383719.html#a12497122
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: write translated messages in renderhead

Posted by Matej Knopp <ma...@gmail.com>.
It's easier to just call getString("key") instead of using
ResourceModel in this case.

-Matej

On 9/5/07, Johan Compagner <jc...@gmail.com> wrote:
> String js += "var myMsg = '" + JavascriptUtils.escapeQuotes(new
> ResourceModel("MY_MSG", null) + "") + "';";
>
> that looks a bit wrong, try something like this
>
> String js += "var myMsg = '" + JavascriptUtils.escapeQuotes(new
> ResourceModel("MY_MSG", null).getObject() + "") + "';";
>
> On 9/5/07, Marieke Vandamme <ma...@tvh.be> wrote:
> >
> >
> > Hello,
> >
> > With new 1.3beta3 release I changed all the entries from
> > StringResourceModel
> > to ResourceModel to avoid the warning 'Tried to retrieve a localized
> > string
> > for a component that has not yet been added to the page.' (I still get
> > this
> > warning when using <wicket:message key=""/> tag.. but I guess that's a
> > bug.)
> >
> > But now my real problem :
> > I'm using the renderHead from IHeaderContributor to print some translated
> > text in javascript.
> >
> > public void renderHead(IHeaderResponse hr) {
> >     String js += "var myMsg = '" + JavascriptUtils.escapeQuotes(new
> > ResourceModel("MY_MSG", null) + "") + "';";
> >     hr.renderJavascript(js, null);
> > }
> >
> > But now the result on my html-page is :
> >
> > var myMsg = 'Model:classname=[org.apache.wicket.model.ResourceModel]';
> >
> > instead I want my translated "MY_MSG".
> > Thanks for your help !
> > --
> > View this message in context:
> > http://www.nabble.com/write-translated-messages-in-renderhead-tf4383719.html#a12496870
> > 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
> >
> >
>

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


Re: write translated messages in renderhead

Posted by Johan Compagner <jc...@gmail.com>.
String js += "var myMsg = '" + JavascriptUtils.escapeQuotes(new
ResourceModel("MY_MSG", null) + "") + "';";

that looks a bit wrong, try something like this

String js += "var myMsg = '" + JavascriptUtils.escapeQuotes(new
ResourceModel("MY_MSG", null).getObject() + "") + "';";

On 9/5/07, Marieke Vandamme <ma...@tvh.be> wrote:
>
>
> Hello,
>
> With new 1.3beta3 release I changed all the entries from
> StringResourceModel
> to ResourceModel to avoid the warning 'Tried to retrieve a localized
> string
> for a component that has not yet been added to the page.' (I still get
> this
> warning when using <wicket:message key=""/> tag.. but I guess that's a
> bug.)
>
> But now my real problem :
> I'm using the renderHead from IHeaderContributor to print some translated
> text in javascript.
>
> public void renderHead(IHeaderResponse hr) {
>     String js += "var myMsg = '" + JavascriptUtils.escapeQuotes(new
> ResourceModel("MY_MSG", null) + "") + "';";
>     hr.renderJavascript(js, null);
> }
>
> But now the result on my html-page is :
>
> var myMsg = 'Model:classname=[org.apache.wicket.model.ResourceModel]';
>
> instead I want my translated "MY_MSG".
> Thanks for your help !
> --
> View this message in context:
> http://www.nabble.com/write-translated-messages-in-renderhead-tf4383719.html#a12496870
> 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
>
>