Implement this method on your page. It is new one on WOComponent in WO4:

    public void validationFailedWithException(java.lang.Throwable e,
Object obj, String s)

 This example I ripped out of an existing app...

    public void validationFailedWithException(java.lang.Throwable e,
Object obj, String s){
        if(obj == null) obj = "NULL";
        // allows me to get part of the error string I want...
        int toStackIndex = e.getMessage().indexOf("Stack");
        String message = e.getMessage().substring(0, toStackIndex);

        // This thing gets called on each validation error
        // I take info from each exception even and stuff it
        // into a dict and that into an array
        // I have a special component I place on a page
        // that shows the list of exceptions that happened
        // by WORep'ing over the list of dicts
        NSMutableDictionary dict = new NSMutableDictionary();
        dict.setObjectForKey(message, "message");
        dict.setObjectForKey(e, "exception");
        dict.setObjectForKey(obj, "object");
        dict.setObjectForKey(s, "key");
        exceptionMessageArray.addObject(dict);
    }


Eric Hermanson wrote:
> 
> Hello,
> 
> I have a property of an enterprise object bound directly to a
> WOTextField.  When the user enters a value into the text field, the
> WOAssociation sets the value on the EO immediately after the form is
> submitted.  This has the unwanted side effect which results in
> validateTakeValue:forKeyPath: getting called immediately thereafter.  If
> the user enter's an invalid value (i.e. a value that is too long to fit
> the width of the property), then the validate method raises an
> exception, as seen in the following backtrace:
> 
> #0  0x320411e0 in -[NSException raise] ()
> #1  0x44022624 in -[NSObject(EOClassDescriptionPrimitives)
> validateTakeValue:forKeyPath:] ()
> #2  0x4203d3ba in -[WOKeyValueAssociation setValue:inComponent:] ()
> #3  0x4202ca68 in -[WOTextField takeValuesFromRequest:inContext:] ()
> #4  0x4202365a in -[WOHTMLDynamicElement(WORequestHandling)
> takeValuesFromRequest:inContext:] ()
> #5  0x420202ba in -[WOForm(WORequestHandling)
> takeValuesFromRequest:inContext:]
> 
> The exception is being caught somewhere (probably by the
> WOKeyValueAssociation).  This has the end result that  1) The value does
> NOT get set on the EO, and 2) The exception does NOT get propagated to
> the editing context when 'tryToSaveChanges' is called.
> 
> This behvaior appears to be markedly different from the behavior in
> WO3.1.  In that version, the end result would have been that the
> validation exception would have been raised (and caught) during
> tryToSaveChanges, thus allowing for intervention (like throwing up an
> alert page).
> 
> Has anyone else noticed this?
> 
> Eric

Reply via email to