Re: [Wonder-disc] ERXValidation Question
Re: [Wonder-disc] ERXValidation Question
- Subject: Re: [Wonder-disc] ERXValidation Question
- From: Chuck Hill <email@hidden>
- Date: Mon, 7 Dec 2009 14:59:42 -0800
On Dec 7, 2009, at 2:51 PM, Johnny Miller wrote:
OK. I think I understand.
Question # 2.
I've changed the validationFailedWithException method to be very
simple
public void validationFailedWithException(Throwable t, Object value,
String keyPath) {
addErrorMessage(t.getMessage);
}
That seems OK.
I have no idea about the question below. If you are using the PWO
validation then this won't work (does not support nesting). I don't
use ERXValidation, so I don't know if that does. The two validations
are not the same and not interchangeable. What they are is quite
similar.
Chuck
In my ValidationTemplate.string file I'm having trouble nesting
exceptions i.e.
if my ValidationTemplate.string file has the following:
{
"MAP_Person.firstName.NullPropertyException" = "Custom Message";
}
I get the right error message (Custom Message).
But if my ValidationTemplate.string file has the following:
{
"MAP_Person" = {
"firstName" = {
"NullPropertyException" = "Custom Message.";
};
};
}
I get the default error
Please provide a <b>First Name</b>.
I watched the WOWDC video on localization by Guido (which was great)
and I thought this was an acceptable way of organizing messages.
Thanks again,
Johnny
On Dec 7, 2009, at 12:38 PM, Chuck Hill wrote:
On Dec 7, 2009, at 2:34 PM, Johnny Miller wrote:
I see.
Can I add this convenience method (from Practical WebObjects) into
my top level component?
You can. I don't know if you want to. You said you were using
ERXValidation and this code is not ERXValidation.
Chuck
@SuppressWarnings("unchecked")
public void validationFailedWithException(Throwable t, Object
value, String keyPath) {
NSBundle bundle = NSBundle.bundleForClass(this.getClass());
String mappingFileName =
bundle
.resourcePathForLocalizedResourceNamed("ValidationTemplate.strings",
null);
byte[] tableBytes = bundle.bytesForResourcePath(mappingFileName);
String tableString = "{" + new String(tableBytes) + "}";
mapping = (NSDictionary<String,
Object
)NSPropertyListSerialization.propertyListFromString(tableString);
if(mapping.objectForKey(t.getMessage()) != null) {
addErrorMessage((String) mapping.objectForKey(t.getMessage()));
} else {
addErrorMessage(t.getMessage());
}
}
Thanks,
Johnny
On Dec 7, 2009, at 12:20 PM, Chuck Hill wrote:
On Dec 7, 2009, at 2:02 PM, Johnny Miller wrote:
Hi,
I'm using ERXValidation for the first time and I'm stuck. I've
added the validation methods to my EOs and I've created the
ValidationTemplate.string file.
In my page I have a "saveChanges" method. I can see that if I
input
an invalid value an errors gets thrown when I save changes on the
editing context. But for some reason the catch never gets
activated.
It is more complicated than that as a validation phase happens
during
takeValueFromRequest. Implement validationFailedWithException:
http://developer.apple.com/legacy/mac/library/documentation/MacOSXServer/Reference/WO54_Reference/com/webobjects/appserver/WOComponent.html#validationFailedWithException(java.lang.Throwable, java.lang.Object, java.lang.String)
And you will have access to the validation message.
Chuck
i.e.
public WOActionResults saveChanges() {
try {
ec().saveChanges();
} catch (ERXValidationException e) {
System.out.println("Catching error message...");
e.printStackTrace();
addErrorMessage(e.getLocalizedMessage());
}
if(hasError()) return null;
return pageWithName(DashboardPage.class);
}
in the console I see
DEBUG NSLog - Validation failed on an object [null] with
keypath =
person.firstName and exception: Please provide a <b>First Name</
b>.
But that's it. The stack trace doesn't print out and the error
message is not added to my errors array. Am I missing a step?
Best,
Johnny
p.s. here is the validation method in my EO.
public String validateFirstName(String value) throws
ERXValidationException {
if(ERXStringUtilities.stringIsNullOrEmpty(value)) {
throw
ERXValidationFactory.defaultFactory().createException(this,
FIRST_NAME_KEY, value,
ERXValidationException.NullPropertyException);
}
return value;
}
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Wonder-disc mailing list
email@hidden
https://lists.sourceforge.net/lists/listinfo/wonder-disc
--
Chuck Hill Senior Consultant / VP Development
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems.
http://www.global-village.net/products/practical_webobjects
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Wonder-disc mailing list
email@hidden
https://lists.sourceforge.net/lists/listinfo/wonder-disc
--
Chuck Hill Senior Consultant / VP Development
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems.
http://www.global-village.net/products/practical_webobjects
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Wonder-disc mailing list
email@hidden
https://lists.sourceforge.net/lists/listinfo/wonder-disc
--
Chuck Hill Senior Consultant / VP Development
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden