You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Zbynek Vavros <zb...@gmail.com> on 2019/01/28 09:43:54 UTC

Validation message parameters and internationalization

So I am using localized version of validation message for required fields

Required=My custom message for field '${label}'

but the resulting message contains field ID as parameters and result is i.e.

"My custom message for field 'password'"

since the whole page is not in English I would like to have the parameter
localized as well.
Some of the users do not speak English and they would not understand what
"password" is.

I see in code of org.apache.wicket.markup.html.form.FormComponent
that the component's getId() is used as parameter. Any way to customize
this?

I can surely use validation message for this specific field with key i.e.
"password.Required"
but I would like to be more generic.

Thanks,
Zbynek

Re: Validation message parameters and internationalization

Posted by Martin Grigorov <mg...@apache.org>.
or use Java 8 goodies ;-)

setLabel(() -> getString("label_key"));

On Mon, Jan 28, 2019 at 1:29 PM Maxim Solodovnik <so...@gmail.com>
wrote:

> Yes,
>
> ResourceModel seems to be much better to use in this case
> Not the best example :(
>
> On Mon, 28 Jan 2019 at 18:24, Ernesto Reinaldo Barreiro <
> reiern70@gmail.com>
> wrote:
>
> > Hi,
> >
> > On Mon, Jan 28, 2019 at 1:04 PM Maxim Solodovnik <so...@gmail.com>
> > wrote:
> >
> > > Hello Zbynek,
> > >
> > > In our project we are customizing validation messages as follows:
> > >
> > > Markup:
> > > <label wicket:for="wicketid"><wicket:message key="label_key" /></label>
> > > <input type="text" wicket:id="wicketid" />
> > >
> > > Java:
> > > add(new
> > >
> > >
> >
> RequiredTextField<String>("wicketid").setLabel(Model.of(getString("label_key"))));
> > >
> >
> > But this will make serialized pages bigger, if key values are bigger
> > compared to keys, as deach on resource model will keep key and discard
> > value (if I'm not mistaken).
> >
> >
> > >
> > > This way lots of built-in validation messages will be "auto-customized"
> > >
> > > not sure if it will work for you
> > >
> > >
> > > On Mon, 28 Jan 2019 at 16:44, Zbynek Vavros <zb...@gmail.com>
> > > wrote:
> > >
> > > > So I am using localized version of validation message for required
> > fields
> > > >
> > > > Required=My custom message for field '${label}'
> > > >
> > > > but the resulting message contains field ID as parameters and result
> is
> > > > i.e.
> > > >
> > > > "My custom message for field 'password'"
> > > >
> > > > since the whole page is not in English I would like to have the
> > parameter
> > > > localized as well.
> > > > Some of the users do not speak English and they would not understand
> > what
> > > > "password" is.
> > > >
> > > > I see in code of org.apache.wicket.markup.html.form.FormComponent
> > > > that the component's getId() is used as parameter. Any way to
> customize
> > > > this?
> > > >
> > > > I can surely use validation message for this specific field with key
> > i.e.
> > > > "password.Required"
> > > > but I would like to be more generic.
> > > >
> > > > Thanks,
> > > > Zbynek
> > > >
> > >
> > >
> > > --
> > > WBR
> > > Maxim aka solomax
> > >
> >
> >
> > --
> > Regards - Ernesto Reinaldo Barreiro
> >
>
>
> --
> WBR
> Maxim aka solomax
>

Re: Validation message parameters and internationalization

Posted by Maxim Solodovnik <so...@gmail.com>.
Yes,

ResourceModel seems to be much better to use in this case
Not the best example :(

On Mon, 28 Jan 2019 at 18:24, Ernesto Reinaldo Barreiro <re...@gmail.com>
wrote:

> Hi,
>
> On Mon, Jan 28, 2019 at 1:04 PM Maxim Solodovnik <so...@gmail.com>
> wrote:
>
> > Hello Zbynek,
> >
> > In our project we are customizing validation messages as follows:
> >
> > Markup:
> > <label wicket:for="wicketid"><wicket:message key="label_key" /></label>
> > <input type="text" wicket:id="wicketid" />
> >
> > Java:
> > add(new
> >
> >
> RequiredTextField<String>("wicketid").setLabel(Model.of(getString("label_key"))));
> >
>
> But this will make serialized pages bigger, if key values are bigger
> compared to keys, as deach on resource model will keep key and discard
> value (if I'm not mistaken).
>
>
> >
> > This way lots of built-in validation messages will be "auto-customized"
> >
> > not sure if it will work for you
> >
> >
> > On Mon, 28 Jan 2019 at 16:44, Zbynek Vavros <zb...@gmail.com>
> > wrote:
> >
> > > So I am using localized version of validation message for required
> fields
> > >
> > > Required=My custom message for field '${label}'
> > >
> > > but the resulting message contains field ID as parameters and result is
> > > i.e.
> > >
> > > "My custom message for field 'password'"
> > >
> > > since the whole page is not in English I would like to have the
> parameter
> > > localized as well.
> > > Some of the users do not speak English and they would not understand
> what
> > > "password" is.
> > >
> > > I see in code of org.apache.wicket.markup.html.form.FormComponent
> > > that the component's getId() is used as parameter. Any way to customize
> > > this?
> > >
> > > I can surely use validation message for this specific field with key
> i.e.
> > > "password.Required"
> > > but I would like to be more generic.
> > >
> > > Thanks,
> > > Zbynek
> > >
> >
> >
> > --
> > WBR
> > Maxim aka solomax
> >
>
>
> --
> Regards - Ernesto Reinaldo Barreiro
>


-- 
WBR
Maxim aka solomax

Re: Validation message parameters and internationalization

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
Hi,

On Mon, Jan 28, 2019 at 1:04 PM Maxim Solodovnik <so...@gmail.com>
wrote:

> Hello Zbynek,
>
> In our project we are customizing validation messages as follows:
>
> Markup:
> <label wicket:for="wicketid"><wicket:message key="label_key" /></label>
> <input type="text" wicket:id="wicketid" />
>
> Java:
> add(new
>
> RequiredTextField<String>("wicketid").setLabel(Model.of(getString("label_key"))));
>

But this will make serialized pages bigger, if key values are bigger
compared to keys, as deach on resource model will keep key and discard
value (if I'm not mistaken).


>
> This way lots of built-in validation messages will be "auto-customized"
>
> not sure if it will work for you
>
>
> On Mon, 28 Jan 2019 at 16:44, Zbynek Vavros <zb...@gmail.com>
> wrote:
>
> > So I am using localized version of validation message for required fields
> >
> > Required=My custom message for field '${label}'
> >
> > but the resulting message contains field ID as parameters and result is
> > i.e.
> >
> > "My custom message for field 'password'"
> >
> > since the whole page is not in English I would like to have the parameter
> > localized as well.
> > Some of the users do not speak English and they would not understand what
> > "password" is.
> >
> > I see in code of org.apache.wicket.markup.html.form.FormComponent
> > that the component's getId() is used as parameter. Any way to customize
> > this?
> >
> > I can surely use validation message for this specific field with key i.e.
> > "password.Required"
> > but I would like to be more generic.
> >
> > Thanks,
> > Zbynek
> >
>
>
> --
> WBR
> Maxim aka solomax
>


-- 
Regards - Ernesto Reinaldo Barreiro

Re: Validation message parameters and internationalization

Posted by Maxim Solodovnik <so...@gmail.com>.
Hello Zbynek,

In our project we are customizing validation messages as follows:

Markup:
<label wicket:for="wicketid"><wicket:message key="label_key" /></label>
<input type="text" wicket:id="wicketid" />

Java:
add(new
RequiredTextField<String>("wicketid").setLabel(Model.of(getString("label_key"))));

This way lots of built-in validation messages will be "auto-customized"

not sure if it will work for you


On Mon, 28 Jan 2019 at 16:44, Zbynek Vavros <zb...@gmail.com> wrote:

> So I am using localized version of validation message for required fields
>
> Required=My custom message for field '${label}'
>
> but the resulting message contains field ID as parameters and result is
> i.e.
>
> "My custom message for field 'password'"
>
> since the whole page is not in English I would like to have the parameter
> localized as well.
> Some of the users do not speak English and they would not understand what
> "password" is.
>
> I see in code of org.apache.wicket.markup.html.form.FormComponent
> that the component's getId() is used as parameter. Any way to customize
> this?
>
> I can surely use validation message for this specific field with key i.e.
> "password.Required"
> but I would like to be more generic.
>
> Thanks,
> Zbynek
>


-- 
WBR
Maxim aka solomax

Re: Validation message parameters and internationalization

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

You should use FormComponent.setLabel(IModel<String>). The parameter most
probably will be ResourceModel.
https://github.com/apache/wicket/blob/684c297cc79f169eeced9e124e7a7e5fe81fb774/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java#L1018-L1030

On Mon, Jan 28, 2019 at 11:44 AM Zbynek Vavros <zb...@gmail.com>
wrote:

> So I am using localized version of validation message for required fields
>
> Required=My custom message for field '${label}'
>
> but the resulting message contains field ID as parameters and result is
> i.e.
>
> "My custom message for field 'password'"
>
> since the whole page is not in English I would like to have the parameter
> localized as well.
> Some of the users do not speak English and they would not understand what
> "password" is.
>
> I see in code of org.apache.wicket.markup.html.form.FormComponent
> that the component's getId() is used as parameter. Any way to customize
> this?
>
> I can surely use validation message for this specific field with key i.e.
> "password.Required"
> but I would like to be more generic.
>
> Thanks,
> Zbynek
>

Re: Validation message parameters and internationalization

Posted by Florian Lacreuse <fl...@kobalt.fr>.
Hi,

You need to set the label model on your FormComponent, component id is 
used as a fallback.

See Wicket guide: 
https://ci.apache.org/projects/wicket/guide/8.x/single.html#_feedback_messages_and_localization


Kind regards,

Florian Lacreuse

Le 28/01/2019 à 10:43, Zbynek Vavros a écrit :
> So I am using localized version of validation message for required fields
>
> Required=My custom message for field '${label}'
>
> but the resulting message contains field ID as parameters and result is i.e.
>
> "My custom message for field 'password'"
>
> since the whole page is not in English I would like to have the parameter
> localized as well.
> Some of the users do not speak English and they would not understand what
> "password" is.
>
> I see in code of org.apache.wicket.markup.html.form.FormComponent
> that the component's getId() is used as parameter. Any way to customize
> this?
>
> I can surely use validation message for this specific field with key i.e.
> "password.Required"
> but I would like to be more generic.
>
> Thanks,
> Zbynek
>
-- 
Kobalt <https://www.kobalt.fr/> 	
Florian Lacreuse
Lead developer · Expert Java / UX
06 95 57 48 57
www.kobalt.fr <https://www.kobalt.fr/>