How to tackle field labels when using CompoundPropertyModels?

2010-12-16 Thread Matthias Keller

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 RequiredTextFieldString(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 RequiredTextFieldString(somepage.name, new 
PropertyModelString(model, name)));

which kinda defeats the whole CompoundPropertyModel stuff

Thanks a lot

Matt



smime.p7s
Description: S/MIME Cryptographic Signature


Re: How to tackle field labels when using CompoundPropertyModels?

2010-12-16 Thread James Carman
You can use page or component scoped messages.

On Thu, Dec 16, 2010 at 11:48 AM, Matthias Keller
matthias.kel...@ergon.ch wrote:
 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 RequiredTextFieldString(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 RequiredTextFieldString(somepage.name, new
 PropertyModelString(model, name)));
 which kinda defeats the whole CompoundPropertyModel stuff

 Thanks a lot

 Matt



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



Re: How to tackle field labels when using CompoundPropertyModels?

2010-12-16 Thread Matthias Keller

Hi James

Do you mean page or component scoped message properties files? Like 
MyPage.properties?
Unfortunately I don't see that as a solution because this would produce 
hundreds or properties files which would be a real nightmare to maintain 
(our customer wants *very* frequent text changes which are way easier to 
do if all translations are in one big file and also enables us to just 
send the customer one file for translation instead of hundreds).

Or is there another way to specify a prefix for a given component?

Thanks

Matt

On 2010-12-16 17:51, James Carman wrote:

You can use page or component scoped messages.

On Thu, Dec 16, 2010 at 11:48 AM, Matthias Keller
matthias.kel...@ergon.ch  wrote:

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 RequiredTextFieldString(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 RequiredTextFieldString(somepage.name, new
PropertyModelString(model, name)));
which kinda defeats the whole CompoundPropertyModel stuff

Thanks a lot

Matt







smime.p7s
Description: S/MIME Cryptographic Signature


Re: How to tackle field labels when using CompoundPropertyModels?

2010-12-16 Thread Bas Gooren

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 CompoundPropertyModelX(...)
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 RequiredTextFieldString(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 RequiredTextFieldString(somepage.name, new
PropertyModelString(model, name)));
which kinda defeats the whole CompoundPropertyModel stuff

Thanks a lot

Matt



smime.p7s
Description: S/MIME cryptographic signature


Re: How to tackle field labels when using CompoundPropertyModels?

2010-12-16 Thread James Carman
You could use a class-qualified key
(com.myco.domain.entity.Person.name=My Name).

On Thu, Dec 16, 2010 at 11:55 AM, Matthias Keller
matthias.kel...@ergon.ch wrote:
 Hi James

 Do you mean page or component scoped message properties files? Like
 MyPage.properties?
 Unfortunately I don't see that as a solution because this would produce
 hundreds or properties files which would be a real nightmare to maintain
 (our customer wants *very* frequent text changes which are way easier to do
 if all translations are in one big file and also enables us to just send the
 customer one file for translation instead of hundreds).
 Or is there another way to specify a prefix for a given component?

 Thanks

 Matt

 On 2010-12-16 17:51, James Carman wrote:

 You can use page or component scoped messages.

 On Thu, Dec 16, 2010 at 11:48 AM, Matthias Keller
 matthias.kel...@ergon.ch  wrote:

 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 RequiredTextFieldString(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 RequiredTextFieldString(somepage.name, new
 PropertyModelString(model, name)));
 which kinda defeats the whole CompoundPropertyModel stuff

 Thanks a lot

 Matt






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



Re: How to tackle field labels when using CompoundPropertyModels?

2010-12-16 Thread James Carman
You could also look at the way Wicketopia does what you're talking about:

https://wicketopia.svn.sourceforge.net/svnroot/wicketopia/trunk/wicketopia/src/main/java/org/wicketopia/model/label/PropertyLabelModel.java

It's a metadata-driven approach.

On Thu, Dec 16, 2010 at 11:58 AM, James Carman
ja...@carmanconsulting.com wrote:
 You could use a class-qualified key
 (com.myco.domain.entity.Person.name=My Name).

 On Thu, Dec 16, 2010 at 11:55 AM, Matthias Keller
 matthias.kel...@ergon.ch wrote:
 Hi James

 Do you mean page or component scoped message properties files? Like
 MyPage.properties?
 Unfortunately I don't see that as a solution because this would produce
 hundreds or properties files which would be a real nightmare to maintain
 (our customer wants *very* frequent text changes which are way easier to do
 if all translations are in one big file and also enables us to just send the
 customer one file for translation instead of hundreds).
 Or is there another way to specify a prefix for a given component?

 Thanks

 Matt

 On 2010-12-16 17:51, James Carman wrote:

 You can use page or component scoped messages.

 On Thu, Dec 16, 2010 at 11:48 AM, Matthias Keller
 matthias.kel...@ergon.ch  wrote:

 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 RequiredTextFieldString(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 RequiredTextFieldString(somepage.name, new
 PropertyModelString(model, name)));
 which kinda defeats the whole CompoundPropertyModel stuff

 Thanks a lot

 Matt







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