• 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 retruns the same page
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Validation retruns the same page


  • Subject: Re: Validation retruns the same page
  • From: Florijan Stamenkovic <email@hidden>
  • Date: Fri, 27 May 2005 20:49:02 +0200


On May 27, 2005, at 18:57, Sacha Mallais wrote:


On May 27, 2005, at 7:59 AM, Florijan Stamenkovic wrote:

On May 27, 2005, at 13:56, email@hidden wrote:

Hello,
after an error happend.

After the form submitted values that failed validation (for example not typing in a field that requires it)

the method
-------------------------------------------------------------------
public void validationFailedWithException( Throwable e, Object value,
String keyPath )
{
}
-------------------------------------------------------------------
will execute.
My question is, how can i return the same page where the error happend?



What I do when I am forced to use validationFailedWithException(), is that I set a boolean invalidInput = true within it. As validationFailedWith... is called just after submitting the form, and since normally a method is performed just after it, I just check my boolean to see if validationFailedWithException failed, and return the same page then. Of course, you must reset your boolean in awake() (i do it in sleep()) methods of the component, otherwise it stays around forever...


This is the right idea, though I would extend it to handle more than one error at a time. Insert error message into an array or something along those lines, then make a method hasErrors() that just returns errors.count() > 0;

I did see some examples on that and did consider it, but then I have to scan keypaths and that's a lot of work, so I skip it until I will have a project really in production. For the time being we are just learning-developing and test deploying... User friendliness is not of high priority. So I just have one error message.



After validationFailedWithException is called, your action method will be called, so in any method that it matters, you should have something along the lines of
if (hasErrors())
{
// display an error message and...
return this
}
else
{
// save the eo and...
return next page
}



I am not sure this is a good pattern to make. I ONLY use it when I have to edit an EO. That is because if I have that EO, and it is old, and it is by itself ok, then if on submit you fail validation with your changes, the changes will not be applied, and you can not validate your object in the invokeAction phase. I mean, you can, but you will not see the changes because they will not be applied. If it is a new EO, with no values set yet, then I ignore validationFailedWith.. and just call validateForSave on the EO in my action.

If you need to view/save the values, you can do so in validationFailedWithException. You can even force them into the EO by bypassing validation and setting the value directly.

Yup, didn't think of it. It is similar to storing them in a dictionary first in a way. Approx. the same amount of code I guess (or even more)... Still, a good approach for add/edit components... Until now I was just storing informing the user that the changes were not ok, and that the record has been reset to old values.. Again, user friendliness not being up to the level... I do put a "please" where ever I can think of though :)


Thanks
Flor



sacha


_______________________________________________ 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: Validation retruns the same page
      • From: mmalcolm crawford <email@hidden>
References: 
 >Re: Default values in EOF (From: Ricardo Strausz <email@hidden>)
 >Validation retruns the same page (From: email@hidden)
 >Re: Validation retruns the same page (From: Florijan Stamenkovic <email@hidden>)
 >Re: Validation retruns the same page (From: Sacha Mallais <email@hidden>)

  • Prev by Date: Re: Display Null value with Raw Rows
  • Next by Date: [OT] WO Pub Night at WWDC?
  • Previous by thread: Re: Validation retruns the same page
  • Next by thread: Re: Validation retruns the same page
  • Index(es):
    • Date
    • Thread