• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [projectwonder/wonder] 3ecb42: Provide a delegate to override the built in ERD2W ...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [projectwonder/wonder] 3ecb42: Provide a delegate to override the built in ERD2W ...


  • Subject: Re: [projectwonder/wonder] 3ecb42: Provide a delegate to override the built in ERD2W ...
  • From: Fabian Peters <email@hidden>
  • Date: Mon, 30 Apr 2012 16:49:25 +0000

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@hidden>
>  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@hidden>.
> To unsubscribe, E-mail to: <email@hidden>
> To switch to the DIGEST mode, E-mail to <email@hidden>
> To switch to the INDEX mode, E-mail to <email@hidden>
> Send administrative queries to  <email@hidden>
>


 _______________________________________________
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

  • Follow-Ups:
    • Re: [projectwonder/wonder] 3ecb42: Provide a delegate to override the built in ERD2W ...
      • From: Ramsey Gurley <email@hidden>
  • Prev by Date: Re: Connection reset by peer: Amount read didn't match content-length in AJP Configuration
  • Next by Date: Re: [projectwonder/wonder] 3ecb42: Provide a delegate to override the built in ERD2W ...
  • Previous by thread: Re: Connection reset by peer: Amount read didn't match content-length in AJP Configuration
  • Next by thread: Re: [projectwonder/wonder] 3ecb42: Provide a delegate to override the built in ERD2W ...
  • Index(es):
    • Date
    • Thread