Hi Matthias,

There are several options, but most importantly: there is special handling for this on FormComponent (see LabeledWebMarkupContainer). You could either scope the fields by setting translations per page/panel, but this can get rather tedious.

Another option is to create specialized label models for your form components, which lookup the type of object in the CompoundPropertyModel and use it as a prefix when looking up a translation.

E.g.

new CompoundPropertyModel<X>(...)
new FormComponent("name") under this CPM.

Such a label model would then detect the CPM and use a translation key of X.name;

You could even implement this transparantly by either using a visitor on the form or a component instantiation listener.

Hope this helps.

Bas

----- Original Message ----- From: "Matthias Keller" <matthias.kel...@ergon.ch>
To: "Wicket List" <users@wicket.apache.org>
Sent: Thursday, December 16, 2010 5:48 PM
Subject: How to tackle field labels when using CompoundPropertyModels?


Hi

This is an issue I frequently run into and I haven't found a good
solution yet:
I've got a Form using a CompoundPropertyModel and having lots of fields.
The easy way to do these fields is:
form.add(new RequiredTextField<String>("name"));

The model object has a getter and setter for name, so all works well.
Unfortunately, when the user doesn't enter a valid value, the Required
error message shows up saying something like "Field 'name' is required".
I could have a resource key "name" in my translations but this has the
limitation, that all "name" fields in my whole app are translated the
same way. Maybe one name is a human name, the other one is a machine
name which have different translations...
Is there an easy way to tackle this problem? For example have a prefix
prepended to the field name or something else? One thing I want to avoid
is to set an explicit label model for every field and if possible I'm
hoping to avoid having to create different TextField subclasses for all
my pages just prepending that string....

How do you do this for large applications?
Currently, we're reverting to
form.add(new RequiredTextField<String>("somepage.name", new
PropertyModel<String>(model, "name")));
which kinda defeats the whole CompoundPropertyModel stuff....

Thanks a lot

Matt

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to