On 12/11/2009, at 5:39 AM, Riccardo De Menna wrote:

I'd like some help in figuring out if what I'm doing has dangerous implications. EOF objects that are edited in WOComponents go through two validations for what I see. The first is done on assignment by WOComponent and the second by EOCustomObject on save.

This can sometimes hamper my ui as for example when using tabs to edit values of a complex EO in steps. Having validation to occur on assignment right away means that my user can't leave a tab if he has not filled the mandatory fields of a new object. And it might be convenient to let him do it sometimes and just check everything when he pushes the save button.

So I added the following to my 'common' EOGenericRecord subclass:

public boolean postponeValidation() {
  return false;
}

@Override
public Object validateTakeValueForKeyPath(Object value, String keyPath) {
  if ( postponeValidation() ) {
      takeValueForKeyPath( value, keyPath );
      return value;
  }
  return super.validateTakeValueForKeyPath(value,keyPath);
}

My eo's can override the postponeValidation and return true to force assignments to occur anyway and just leave it to the save-validation to catch any errors. Am I doing something I will regret here? Can you foresee problems in using such practice?

Yeah the problem with this is that the value might actually be invalid. e.g., a String when you expect an Integer. So your takeValueForKeyPath will fail anyway.

In my [EO|ERX]GenericRecord subclass (which all my other entities inherit from) I have this:

private final Map< String, Object > _invalidValues;
public ISHGenericRecord()
{
        super();
this._invalidValues = Collections.synchronizedMap( new HashMap< String, Object >( entity() == null ? 0 : entity().attributes().count() * 2 ) );
}

public Object invalidValueForKey( String key )
{
        return this._invalidValues.get( key );
}

public void setInvalidValueForKey( Object aValue, String key )
{
        if ( aValue == null )
        {
                this._invalidValues.remove( key );
        }
        else
        {
                this._invalidValues.put( key, aValue );
        }
}

@Override
public Object valueForKey( String key )
{
        if ( !( editingContext() instanceof EOSharedEditingContext ) )
        {
                Object result = invalidValueForKey( key );
                if ( result != null )
                {
                        return result;
                }
        }
        return super.valueForKey( key );
}

Then, throw your normal validation exceptions and have the page itself inherit from (or slight modification of in my case) Chuck Hill and Sacha Mallais' ValidatingPage component (see GVCFrameworks or PracticalUtilities download for the book Practical WebObjects) to record all the validation errors for the page during takeValueFromRequest.

with regards,
--

Lachlan Deck

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

This email sent to arch...@mail-archive.com

Reply via email to