You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Thorsten Schöning <ts...@am-soft.de> on 2015/02/17 17:58:01 UTC

WicketMessageResolver, Message Container and variable substitution

Hi all,

I have a panel with some wicket:message keys with some text out of
property files and would like to input some variables in there with
values coming from a global configuration. What I do not want to do is
to create a label for each message just to provide my map for variable
substitution, I would like to have some more automatic approach.

I had a look at WicketMessageResolver and it's private
MessageContainer and the latter seems to be capable of doing variable
substitution from e.g. a default model of a component. The problem
seems to be that this only takes the direct parent of the
wicke:message-object into account which is some
TransparentMarkupContainer I don't seem to have access to. The parent
of that TransparentMarkupContainer is my panel, but I'm simply unable
to find any way to tell MessageContainer to use the default model of
my panel or something else I have provided.

I don't seem to understand how this is supposed to work as the
TransparentMarkupContainer is automatically created by Wicket and it
doesn't seem to me that it's parent component has any influence on the
created object to provide it with a default model or whatever.

Could you please enlighten me a bit again and tell me if it's possible
to achieve what I want at all and if so how?

Thanks!

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning       E-Mail: Thorsten.Schoening@AM-SoFT.de
AM-SoFT IT-Systeme      http://www.AM-SoFT.de/

Telefon...........05151-  9468- 55
Fax...............05151-  9468- 88
Mobil..............0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow


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


Re: WicketMessageResolver, Message Container and variable substitution

Posted by Tobias Soloschenko <to...@googlemail.com>.
Hi,

the user guide of Andrea is explaining this very good is there something you are looking for?

http://wicket.apache.org/guide/guide/i18n.html

kind regards

Tobias

> Am 17.02.2015 um 17:58 schrieb Thorsten Schöning <ts...@am-soft.de>:
> 
> Hi all,
> 
> I have a panel with some wicket:message keys with some text out of
> property files and would like to input some variables in there with
> values coming from a global configuration. What I do not want to do is
> to create a label for each message just to provide my map for variable
> substitution, I would like to have some more automatic approach.
> 
> I had a look at WicketMessageResolver and it's private
> MessageContainer and the latter seems to be capable of doing variable
> substitution from e.g. a default model of a component. The problem
> seems to be that this only takes the direct parent of the
> wicke:message-object into account which is some
> TransparentMarkupContainer I don't seem to have access to. The parent
> of that TransparentMarkupContainer is my panel, but I'm simply unable
> to find any way to tell MessageContainer to use the default model of
> my panel or something else I have provided.
> 
> I don't seem to understand how this is supposed to work as the
> TransparentMarkupContainer is automatically created by Wicket and it
> doesn't seem to me that it's parent component has any influence on the
> created object to provide it with a default model or whatever.
> 
> Could you please enlighten me a bit again and tell me if it's possible
> to achieve what I want at all and if so how?
> 
> Thanks!
> 
> Mit freundlichen Grüßen,
> 
> Thorsten Schöning
> 
> -- 
> Thorsten Schöning       E-Mail: Thorsten.Schoening@AM-SoFT.de
> AM-SoFT IT-Systeme      http://www.AM-SoFT.de/
> 
> Telefon...........05151-  9468- 55
> Fax...............05151-  9468- 88
> Mobil..............0178-8 9468- 04
> 
> AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
> AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow
> 
> 
> ---------------------------------------------------------------------
> 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: WicketMessageResolver, Message Container and variable substitution

Posted by Thorsten Schöning <ts...@am-soft.de>.
Guten Tag Thorsten Schöning,
am Dienstag, 17. Februar 2015 um 17:58 schrieben Sie:

> I don't seem to understand how this is supposed to work as the
> TransparentMarkupContainer is automatically created by Wicket and it
> doesn't seem to me that it's parent component has any influence on the
> created object to provide it with a default model or whatever.

I've found the missing part myself: In case of no model for
TransparentMarkupContainer itself it calls through to it's parents
using Component.initModel to give those the chance to provide a model.
The nasty thing here is that a simple default model of a parent is not
enough, only models implementing the special interface
IComponentInheritedModel are accepted and this behavior doesn't seem
to be clearly enough documented to me. My default model was a simple
Map and obviously didn't implement it so it was not taken into
account.

And because the fun never stops, it seems that wicket:message as an
attribute is resolved using another class WicketMessageTagHandler
which implements a different behavior regarding variable substitution
which seems to result in a call to Component.getString without any
model at all:

> final String value;
> if (tag.getAttributes().containsKey(attr))
> {
>         value = component.getString(key, null, tag.getAttributes().getString(attr));
> }
> else
> {
>         value = component.getString(key);
> }

From my point of view both calls should provide the same model as
MessageContainer does, because in both cases the component is a
TransparentWebMarkupContainer with my custom panel as parent, which is
able to provide a default model. I don't see why there should be a
different approach than in MessageContainer.

Additionally it seems there's a misplaced comment in Localizer.getString:

> // If a property value has been found, or a default value was given,
> // than replace the placeholder and we are done
> if (value != null)
> {
>       return value;
> }

There's no replacement done and the one mentioned seems to happen in
getStringIgnoreSettings already.

So half the way done and still no solution...

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning       E-Mail: Thorsten.Schoening@AM-SoFT.de
AM-SoFT IT-Systeme      http://www.AM-SoFT.de/

Telefon...........05151-  9468- 55
Fax...............05151-  9468- 88
Mobil..............0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow


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