If this is only to get localized messages, then you just need to setup ERXLocalizer properly and the messages are automagically localized by Wonder:

e.g. in your Properties:

er.extensions.ERXLocalizer.isLocalizationEnabled = true
er.extensions.ERXLocalizer.frameworkSearchPath = (app,ERExtensions)
er.extensions.ERXLocalizer.fileNamesToWatch = ("Localizable.strings","ValidationTemplate.strings")
er.extensions.ERXLocalizer.defaultLanguage = English
er.extensions.ERXLocalizer.availableLanguages = (English,German)

In "Resources" you create a folder for each language, e.g. English.lproj and German.lproj. In each of those, you put a Localizable.strings and a ValidationTemplate.strings file.

Localizable.string is for "normal" localizations e.g.:

{
        localizerExceptions = {
                "item.0"="Datensätze";
                "item.1"="Datensatz";
                "item"="Datensätze";
        };
        
        "labelSelectFile"="Datei auswählen";
        "labelDeleteFile"="Löschen";
}

ValidationTemplate.strings is for validation messages:

{
"NullPropertyException" = "Bitte füllen Sie das Feld <b>@@displayNameForProperty@@</b> aus."; "User.password.NullPropertyException" = "Kein Passwort? Soll das ein Witz sein?";
}

The way the key is constructed is defined in ERXValidationFactory#templateForEntityPropertyType:

        // 1st try the whole string.
String template = templateForKeyPath(entityName + "." + property + "." + type, targetLanguage);
        // 2nd try everything minus the type.
        if (template == null)
template = templateForKeyPath(entityName + "." + property, targetLanguage);
        // 3rd try property plus type
        if (template == null)
template = templateForKeyPath(property + "." + type, targetLanguage);
        // 4th try just property
        if (template == null)
            template = templateForKeyPath(property, targetLanguage);
        // 5th try just type
        if (template == null)
            template = templateForKeyPath(type, targetLanguage);
        if (template == null) {
template = UNDEFINED_VALIDATION_TEMPLATE + " entity \"" + entityName + "\" property \"" + property + "\" type \"" + type + "\" target language \"" + targetLanguage + "\"";
            log.error(template);
        }


You have access to the ERXValidationException from within the template string using the "@@" notation. E.g. @@object.login@@ is replaced by the value returned by exception.valueForKeyPath ("object.login").

It is also possible to define more complex validations in the userInfo of a property, but I forgot how this is done...

HTH,

Timo






Am 30.01.2009 um 15:38 schrieb WebObjects - Anazys:

Hi all,

I have the same problem that describes in this old mail : a NullPropertyException (from ERXValidationException) is thrown instead of using my validateKey methods.
Has somebody found a solution to that without changing the model ?

Thanks.
Cedric

Le 2 juin 08 à 17:35, Rams a écrit :

Hi everyone,

I have a model object using the WonderEntity template and my validateKey methods are being intercepted higher up with a NullPropertyException (ERXValidationException). I'd like to handle the null values myself and throw a localized exception message, but my validateKey method never gets called if the value is null. Does anyone know how I can catch that null value myself?

Thank you! :-) _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/webobjects% 40anazys.com

This email sent to [email protected]

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/th-dev% 40onlinehome.de

This email sent to [email protected]

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to