• 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: Validation Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Validation Problem


  • Subject: Re: Validation Problem
  • From: Art Isbell <email@hidden>
  • Date: Tue, 9 Dec 2003 12:38:51 -1000

On Tuesday, December 9, 2003, at 10:08  AM, Jonathan Fleming wrote:

Practically all the validation I've ever done has been on EO's, but now I need to validate an int bound to a WOTextField which is only an iVar not an EO. I want to validate for a null value. What would be the best way to do this as I am getting this error at the moment:
Error: java.lang.IllegalArgumentException: [ takeValueForKey()]: Failed to assign null to key 'qty.
Reason: [<ProductItem name: ProductItem subcomponents: null > takeValueForKey()]: Failed to assign null to key 'qty.

I'm guessing that the exception is being thrown because null cannot be assigned to a Java primitive int. If your ivar were a Java Integer, the exception might not be thrown.


But in general, implementing WO and EOF validation such that it does what you want but doesn't validate unnecessarily isn't trivial (IMHO, at least). I started with mmalcolm crawford's "Data validation with WebObjects 5" Stepwise article (http://www.stepwise.com/Articles/Technical/2001-06-13.01.html), added a dash of Andrew Lindesay's "Keeping Invalid Data with WebObjects Components" Stepwise article (http://www.stepwise.com/Articles/Technical/2003-09-29.01.html), and added my own modifications to deal with particular Web page designs (e.g., validating values entered in text fields, popup lists, etc. in repetitions).

I create a WOComponent subclass that encapsulates common validation code. Then each WOComponent that needs validation inherits from this validation component. The validation component maintains an array of keys to be validated (the actual keys are provided by subclasses). These can be EO attributes and WO component keys. Only when a component is first displayed (in appendToResponse()) do I validate all keys to catch invalid database values and/or to print a validation message on the component by all required values when a new EO is being created. I again validate all keys in takeValuesFromRequest() to catch invalid values and to prevent saving if validation errors occur.

	This validation component maintains a data structure:

validationFlags =
{
     key0 =
     {
         Failed = <Boolean>;
         Message = <String>;
     };
     ...
     keyn =
     {
         Failed = <Boolean>;
         Message = <String>;
     };
     Other =
     {
         Failed = <Boolean>;
         Message = <String>;
     };
 }

I have built a simple ValidationMessage custom subcomponent that includes a WOConditional ("condition" key bound to validationFlags.keyx.Failed) containing a WOTextField whose "value" key is bound to validationFlags.keyx.Message. validationFlags.Other is reserved for exceptions that aren't specific to a particular key such as those thrown from validateForSave(), editing context save exceptions, etc. I include a ValidationMessage for these "Other" exceptions on the component where the user can easily see it.

My validationFailedWithException() override in my validation component deals with EO attributes, WO keys, and any other key path.

The method that validates all keys iterates through all keys in the array of validation keys. If the validationFlags data structure indicates that validation hasn't already failed, it asks the EO to validate the value of the key. If the EO has no such key, it asks the component to validate the key.

I need to do some more checking to ensure that I'm not validating more than necessary since I'm setting validationFlags in both validationFailedWithException() and in my method that validates all keys. I repeat that validation doesn't seem easy to do correctly.

But validation of WO component keys that aren't EO attributes can certainly be included within WO's validation support.

Aloha,
Art
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Validation Problem (From: "Jonathan Fleming" <email@hidden>)

  • Prev by Date: Re: Validation Problem
  • Next by Date: 4th Dimension use with EOModeler?
  • Previous by thread: Re: Validation Problem
  • Next by thread: Additional VM options
  • Index(es):
    • Date
    • Thread