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

Re: takeValuesFromForm Validation


  • Subject: Re: takeValuesFromForm Validation
  • From: Lachlan Deck <email@hidden>
  • Date: Wed, 1 Aug 2007 13:36:57 +1000

Hi Owen,

On 01/08/2007, at 12:18 PM, Owen McKerrow wrote:

I have an attribute in an entity that has a width of 1500 char. I have over ridden the validate method for it inside the entities java class.....

public String validateRqfJustification(String newState) throws NSValidation.ValidationException
{
if ( newState != null ) {
if (newState.length() > 1500) {
throw new NSValidation.ValidationException("The RQF Justification can not be longer than 1500 characters");
}
}
return newState;
}


This gets called fine when I try to save it.

However if I submit the form and the text field contains more than 1500 chars, a validation error is thrown, without going into this method because it checks it against the width inside the model.

I catch this exception inside the component validationFailedWithException() method, the page gets return I display the error message ( not the nicely formatted one form above, but the default one ). BUT the value of the form in the feild has been reset to what it was before they click the button. This is not what I want. I want to tell them they can't save but the value in the field should stay the same as what they just typed.

You might want to check out Practical WebObjects chapter 5.. PracticalUtilities framework.


So 2 questions :
1) When a form is submitted why doesn't it use my validation method for that attribute ? What validation is it calling ? i.e. validateforUpdate() ?

validateForUpdate will be called on an existing record prior to save. The above should be called during the validateTakeValues... phase.


2) How can I get the value the user typed to stay in the form, instead of being truncated back ?

That's something I'm working on at the moment actually... something like...


public String validateRqfJustification(String newState) throws NSValidation.ValidationException
{
if ( newState != null ) {
if (newState.length() > 1500) {
this._invalidValues.takeValueForKey(newState, ValidateRqfJustificationKey);
throw new NSValidation.ValidationException("The RQF Justification can not be longer than 1500 characters");
}
}
this._invalidValues.takeValueForKey(null, ValidateRqfJustificationKey);
return newState;
}


public Object valueForKey(String key) {
	Object result = this._invalidValues.valueForKey(key);
	if (result != null) return result;
	return super.valueForKey(key);
}
etc

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


References: 
 >takeValuesFromForm Validation (From: Owen McKerrow <email@hidden>)

  • Prev by Date: takeValuesFromForm Validation
  • Previous by thread: takeValuesFromForm Validation
  • Index(es):
    • Date
    • Thread