Re: Postponed validation possible?

2009-11-12 Thread Riccardo De Menna
 Oh, and the push changes thing appears to be controlled by a property. It 
 appears that if you want to turn it on you would put
 
 er.extensions.ERXValidationShouldPushChangesToObject=true
 
 In your properties file.

It doesn't seem to work for me. Even though I turn it on, a model based 
exception due to non null field that has been left empty doesn't get pushed.
I'm not sure to grasp all the flow of it, but for what I see the push setting 
acts when an old NSValidation.ValidationException gets converted through the 
ERXValidation class.
Backstepping the validation the main point where this could happen but doesn't 
(in my particular case) looks like ERD2WPage. The code checks for e instanceof 
ERXValidationException and since it's already the case, no call to 
ERXValidation is made and so no pushing is honored.

I can obviously call it myself... but is there a more appropriate way? Anjo?

rdm ___
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


Re: Postponed validation possible?

2009-11-12 Thread Anjo Krank
Gee, it's been 5 years since I last touched this...

You need to override 

public void validationFailedWithException(Throwable e, Object value, String 
keyPath) {

in your page and have code similar to the stuff in ERD2WPage, also you need to 
extend ERXGenRec and let it use ERXEntityClassDesc. And your component needs to 
call parent().validationFailedWithException();

Cheers, Anjo



Am 12.11.2009 um 18:45 schrieb Riccardo De Menna:

 Oh, and the push changes thing appears to be controlled by a property. It 
 appears that if you want to turn it on you would put
 
 er.extensions.ERXValidationShouldPushChangesToObject=true
 
 In your properties file.
 
 It doesn't seem to work for me. Even though I turn it on, a model based 
 exception due to non null field that has been left empty doesn't get pushed.
 I'm not sure to grasp all the flow of it, but for what I see the push setting 
 acts when an old NSValidation.ValidationException gets converted through the 
 ERXValidation class.
 Backstepping the validation the main point where this could happen but 
 doesn't (in my particular case) looks like ERD2WPage. The code checks for e 
 instanceof ERXValidationException and since it's already the case, no call 
 to ERXValidation is made and so no pushing is honored.
 
 I can obviously call it myself... but is there a more appropriate way? Anjo?
 
 rdm ___
 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/anjo%40krank.net
 
 This email sent to a...@krank.net

 ___
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


Postponed validation possible?

2009-11-11 Thread Riccardo De Menna
Hi,

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?

rdm ___
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


Re: Postponed validation possible?

2009-11-11 Thread Chuck Hill


On Nov 11, 2009, at 10:39 AM, Riccardo De Menna wrote:


Hi,

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?



AFAIK validateTakeValueForKeyPath is only used by bindings during the  
takeValuesFromRequest phase of the RR loop.  What you are doing should  
be safe.



Chuck


--
Chuck Hill Senior Consultant / VP Development

Practical WebObjects - for developers who want to increase their  
overall knowledge of WebObjects or who are trying to solve specific  
problems.

http://www.global-village.net/products/practical_webobjects







___
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


Re: Postponed validation possible?

2009-11-11 Thread Lachlan Deck

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


Re: Postponed validation possible?

2009-11-11 Thread Lachlan Deck

On 12/11/2009, at 7:16 AM, Chuck Hill wrote:


On Nov 11, 2009, at 10: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?


AFAIK validateTakeValueForKeyPath is only used by bindings during  
the takeValuesFromRequest phase of the RR loop.  What you are doing  
should be safe.


Chuck needs more Coffee :-)

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


Re: Postponed validation possible?

2009-11-11 Thread Anjo Krank
 @Override
 public Object valueForKey( String key )
 {

This actually works? Yikes! Why not simply push the value to the EO and be done 
with it? If it's invalid, the EC can't save and will throw validation errors 
and it will be restored on the next revert().

Cheers, Anjo


 ___
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


Re: Postponed validation possible?

2009-11-11 Thread Lachlan Deck

On 12/11/2009, at 8:49 AM, Anjo Krank wrote:


@Override
public Object valueForKey( String key )
{


This actually works? Yikes!


Yes.

Why not simply push the value to the EO and be done with it? If it's  
invalid, the EC can't save and will throw validation errors and it  
will be restored on the next revert().


Because then the user loses what they typed which can sometimes be  
annoying (e.g., if it's too long a string etc)


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


Re: Postponed validation possible?

2009-11-11 Thread Anjo Krank
 Because then the user loses what they typed which can sometimes be annoying 
 (e.g., if it's too long a string etc)

As i said: then push the invalid value. This is what ERXValidation does.

Cheers, Anjo


 ___
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


Re: Postponed validation possible?

2009-11-11 Thread Lachlan Deck

On 12/11/2009, at 8:53 AM, Anjo Krank wrote:

Because then the user loses what they typed which can sometimes be  
annoying (e.g., if it's too long a string etc)


As i said: then push the invalid value. This is what ERXValidation  
does.


And if the value's of the wrong type or can't be coerced?

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


Re: Postponed validation possible?

2009-11-11 Thread Anjo Krank
 Because then the user loses what they typed which can sometimes be annoying 
 (e.g., if it's too long a string etc)
 
 As i said: then push the invalid value. This is what ERXValidation does.
 
 And if the value's of the wrong type or can't be coerced?

if (eo instanceof EOEnterpriseObject) {
// the exception is coming from EREnterpriseObject
// WE PUSH THE WRONG VALUE INTO THE EO ANYWAY!
if (pushChanges)  {
try {
((EOEnterpriseObject)eo).takeValueForKeyPath(value, 
key);
} catch(NSKeyValueCoding.UnknownKeyException  ex) {
// AK: as we could have custom components that have 
non-existant keys
// we of course can't push a value, so we discard the 
resulting exception
} catch(Exception ex) {
log.error(Can't push value to key ' + key + ':  + 
value, ex);
}
}

Cheers, Anjo

 ___
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


Re: Postponed validation possible?

2009-11-11 Thread Riccardo De Menna
Ok,

I'm in a wonder-enabled scenario so how do I use it? Need to call 
setPushChangesDefault(true) somewhere?

rdm

On 11/nov/2009, at 14.38, Anjo Krank wrote:

 Because then the user loses what they typed which can sometimes be 
 annoying (e.g., if it's too long a string etc)
 
 As i said: then push the invalid value. This is what ERXValidation does.
 
 And if the value's of the wrong type or can't be coerced?
 
if (eo instanceof EOEnterpriseObject) {
// the exception is coming from EREnterpriseObject
// WE PUSH THE WRONG VALUE INTO THE EO ANYWAY!
if (pushChanges)  {
try {
((EOEnterpriseObject)eo).takeValueForKeyPath(value, 
 key);
} catch(NSKeyValueCoding.UnknownKeyException  ex) {
// AK: as we could have custom components that have 
 non-existant keys
// we of course can't push a value, so we discard the 
 resulting exception
} catch(Exception ex) {
log.error(Can't push value to key ' + key + ':  + 
 value, ex);
}
}
 
 Cheers, Anjo
 
 ___
 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/demenna%40rdm-web.com
 
 This email sent to deme...@rdm-web.com

 ___
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


Re: Postponed validation possible?

2009-11-11 Thread Ramsey Lee Gurley
Nice :-)

I learned something today.

Ramsey

On Nov 11, 2009, at 5:38 PM, Anjo Krank wrote:

 Because then the user loses what they typed which can sometimes be 
 annoying (e.g., if it's too long a string etc)
 
 As i said: then push the invalid value. This is what ERXValidation does.
 
 And if the value's of the wrong type or can't be coerced?
 
if (eo instanceof EOEnterpriseObject) {
// the exception is coming from EREnterpriseObject
// WE PUSH THE WRONG VALUE INTO THE EO ANYWAY!
if (pushChanges)  {
try {
((EOEnterpriseObject)eo).takeValueForKeyPath(value, 
 key);
} catch(NSKeyValueCoding.UnknownKeyException  ex) {
// AK: as we could have custom components that have 
 non-existant keys
// we of course can't push a value, so we discard the 
 resulting exception
} catch(Exception ex) {
log.error(Can't push value to key ' + key + ':  + 
 value, ex);
}
}
 
 Cheers, Anjo
 
 ___
 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/rgurley%40mac.com
 
 This email sent to rgur...@mac.com



smime.p7s
Description: S/MIME cryptographic signature
 ___
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