• 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: Postponed validation possible?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Postponed validation possible?


  • Subject: Re: Postponed validation possible?
  • From: Lachlan Deck <email@hidden>
  • Date: Thu, 12 Nov 2009 08:38:05 +1100

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      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Postponed validation possible?
      • From: Anjo Krank <email@hidden>
References: 
 >Postponed validation possible? (From: Riccardo De Menna <email@hidden>)

  • Prev by Date: Re: Postponed validation possible?
  • Next by Date: Re: Postponed validation possible?
  • Previous by thread: Re: Postponed validation possible?
  • Next by thread: Re: Postponed validation possible?
  • Index(es):
    • Date
    • Thread