I needed it too. Now my login validation errors show up. https://github.com/nullterminated/ponder/blob/master/ERAuth/Sources/er/auth/LoginValidationDelegate.java
I still haven't done list validation on multiple objects with it, but I think there's sufficient flexibility there to do it now. Sorry it took me a month for me to get to it :-) Ramsey On Apr 30, 2012, at 9:49 AM, Fabian Peters wrote: > Ramsey, > > Thanks for this, it's very useful! Much appreciated! > > Fabian > > Am 25.04.2012 um 05:00 schrieb GitHub: > >> Branch: refs/heads/integration >> Home: https://github.com/projectwonder/wonder >> Commit: 3ecb423dd6b575451f85b5f0ced77d655411d84f >> >> https://github.com/projectwonder/wonder/commit/3ecb423dd6b575451f85b5f0ced77d655411d84f >> Author: nullterminated <[email protected]> >> Date: 2012-04-24 (Tue, 24 Apr 2012) >> >> Changed paths: >> M Frameworks/Core/ERDirectToWeb/Sources/er/directtoweb/pages/ERD2WPage.java >> >> Log Message: >> ----------- >> Provide a delegate to override the built in ERD2W validation logic. >> >> >> diff --git >> a/Frameworks/Core/ERDirectToWeb/Sources/er/directtoweb/pages/ERD2WPage.java >> b/Frameworks/Core/ERDirectToWeb/Sources/er/directtoweb/pages/ERD2WPage.java >> index 7a92892..afdaab2 100644 >> --- >> a/Frameworks/Core/ERDirectToWeb/Sources/er/directtoweb/pages/ERD2WPage.java >> +++ >> b/Frameworks/Core/ERDirectToWeb/Sources/er/directtoweb/pages/ERD2WPage.java >> @@ -9,6 +9,9 @@ >> import java.io.IOException; >> import java.io.ObjectInputStream; >> import java.io.ObjectOutputStream; >> +import java.io.Serializable; >> +import java.lang.reflect.Constructor; >> +import java.lang.reflect.InvocationTargetException; >> import java.util.Enumeration; >> import java.util.NoSuchElementException; >> >> @@ -31,11 +34,13 @@ >> import com.webobjects.eocontrol.EOEnterpriseObject; >> import com.webobjects.foundation.NSArray; >> import com.webobjects.foundation.NSDictionary; >> +import com.webobjects.foundation.NSForwardException; >> import com.webobjects.foundation.NSKeyValueCoding; >> import com.webobjects.foundation.NSMutableArray; >> import com.webobjects.foundation.NSMutableDictionary; >> import com.webobjects.foundation.NSMutableSet; >> import com.webobjects.foundation.NSTimestamp; >> +import com.webobjects.foundation._NSUtilities; >> >> import er.directtoweb.ERD2WContainer; >> import er.directtoweb.ERD2WDirectAction; >> @@ -161,7 +166,7 @@ >> public static final String firstResponderKey = >> "firstResponderKey"; >> >> } >> - >> + >> /** logging support */ >> public final static Logger log = Logger.getLogger(ERD2WPage.class); >> >> @@ -364,19 +369,23 @@ public void setLocalContext(D2WContext newValue) { >> // Error handling extensions >> // >> ************************************************************************** >> >> - protected NSMutableDictionary<String,String> errorMessages = new >> NSMutableDictionary<String,String>(); >> + protected NSMutableDictionary errorMessages = new NSMutableDictionary(); >> >> - protected NSMutableArray<String> errorKeyOrder = new >> NSMutableArray<String>(); >> + protected NSMutableArray errorKeyOrder = new NSMutableArray(); >> >> protected NSMutableArray<String> keyPathsWithValidationExceptions = new >> NSMutableArray<String>(); >> >> protected String errorMessage = ""; >> + >> + protected ValidationDelegate validationDelegate; >> + >> + protected boolean validationDelegateInited; >> >> - public NSMutableDictionary<String,String> errorMessages() { >> + public NSMutableDictionary errorMessages() { >> return errorMessages; >> } >> >> - public void setErrorMessages(NSMutableDictionary<String,String> value) { >> + public void setErrorMessages(NSMutableDictionary value) { >> errorMessages = value; >> } >> >> @@ -392,7 +401,7 @@ public boolean hasErrors() { >> return (errorMessages != null && errorMessages.count() > 0) || >> (errorMessage != null && errorMessage.trim().length() > 0); >> } >> >> - public NSArray<String> errorKeyOrder() { >> + public NSArray errorKeyOrder() { >> return errorKeyOrder; >> } >> >> @@ -436,6 +445,10 @@ public void validationFailedWithException(Throwable e, >> Object value, String keyP >> validationLog.debug("Validation failed with exception: " + e + " >> value: " + value + " keyPath: " + keyPath); >> } >> if (shouldCollectValidationExceptions()) { >> + if(validationDelegate() != null) { >> + validationDelegate().validationFailedWithException(e, >> value, keyPath); >> + return; >> + } >> if (e instanceof ERXValidationException) { >> ERXValidationException erv = (ERXValidationException) e; >> >> @@ -505,6 +518,67 @@ public void validationFailedWithException(Throwable e, >> Object value, String keyP >> parent().validationFailedWithException(e, value, keyPath); >> } >> } >> + >> + public ValidationDelegate validationDelegate() { >> + if(shouldCollectValidationExceptions() && >> !validationDelegateInited) { >> + // initialize validation delegate >> + String delegateClassName = >> (String)d2wContext().valueForKey("validationDelegateClassName"); >> + if(delegateClassName != null) { >> + try { >> + Class<? extends ValidationDelegate> >> delegateClass = >> + >> _NSUtilities.classWithName(delegateClassName); >> + if(delegateClass != null) { >> + Constructor<? extends >> ValidationDelegate> constructor = >> + >> delegateClass.getConstructor(ERD2WPage.class); >> + validationDelegate = >> constructor.newInstance(this); >> + } >> + } catch (NoSuchMethodException e) { >> + throw >> NSForwardException._runtimeExceptionForThrowable(e); >> + } catch (IllegalArgumentException e) { >> + throw >> NSForwardException._runtimeExceptionForThrowable(e); >> + } catch (InstantiationException e) { >> + throw >> NSForwardException._runtimeExceptionForThrowable(e); >> + } catch (IllegalAccessException e) { >> + throw >> NSForwardException._runtimeExceptionForThrowable(e); >> + } catch (InvocationTargetException e) { >> + throw >> NSForwardException._runtimeExceptionForThrowable(e); >> + } >> + } >> + validationDelegateInited = true; >> + } >> + return validationDelegate; >> + } >> + >> + public void setValidationDelegate(ValidationDelegate delegate) { >> + validationDelegate = delegate; >> + } >> + >> + public static abstract class ValidationDelegate implements Serializable >> { >> + protected final ERD2WPage _page; >> + >> + public ValidationDelegate(ERD2WPage page) { >> + _page = page; >> + } >> + >> + protected NSMutableDictionary errorMessages() { >> + return _page.errorMessages; >> + } >> + >> + protected NSMutableArray errorKeyOrder() { >> + return _page.errorKeyOrder; >> + } >> + >> + protected String errorMessage() { >> + return _page.errorMessage; >> + } >> + >> + protected void setErrorMessage(String errorMessage) { >> + _page.setErrorMessage(errorMessage); >> + } >> + >> + public abstract boolean hasValidationExceptionForPropertyKey(); >> + public abstract void validationFailedWithException(Throwable e, >> Object value, String keyPath); >> + } >> >> /** Checks if the current object can be edited. */ >> public boolean isObjectEditable() { >> @@ -554,6 +628,9 @@ public boolean isEntityEditable() { >> * current property key. >> */ >> public boolean hasValidationExceptionForPropertyKey() { >> + if(validationDelegate() != null) { >> + return >> validationDelegate().hasValidationExceptionForPropertyKey(); >> + } >> return d2wContext().propertyKey() != null && >> keyPathsWithValidationExceptions.count() != 0 ? >> keyPathsWithValidationExceptions.containsObject(d2wContext().propertyKey()) >> : false; >> } >> >> >> ================================================================ >> >> ############################################################# >> This message is sent to you because you are subscribed to >> the mailing list <[email protected]>. >> To unsubscribe, E-mail to: <[email protected]> >> To switch to the DIGEST mode, E-mail to >> <[email protected]> >> To switch to the INDEX mode, E-mail to <[email protected]> >> Send administrative queries 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: > https://lists.apple.com/mailman/options/webobjects-dev/rgurley%40smarthealth.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: https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to [email protected]
