Virtual method that can be used to hook up validation logic for your business objects. Validation typically gets called before saving an entity.
You override this method and fill the oValidationErrors
property with any errors you find. The method should then return .T.
or .F.
to determine whether validation errors where found.
This method needs to be called explicitly unless lValidateOnSave is set to .T. This method returns .T. by default if not implemented.
o.validate()
Return Value
.T. or .F.
Example
************************************************************************
* ttCustomer :: Validate
****************************************
FUNCTION Validate()
DODEFAULT()
IF EMPTY(this.oData.Company)
this.AddValidationError("Company can't be left empty.","Company")
ENDIF
IF EMPTY(this.oData.LastName)
this.AddValidationError("Lastname must be provided.","LastName")
ENDIF
IF EMPTY(this.oData.FirstName)
this.AddValidationError("Firstname must be provided.","FirstName")
ENDIF
IF EMPTY(this.oData.CountryId)
this.AddValidationError("Country is a required field","CountryId")
ENDIF
*** Determine whether we need to return an error
IF THIS.oValidationErrors.Count > 0
*** Set an error message that summarizes all errors optionally
this.SetError( this.oValidationErrors.ToString() )
*** Validation errors exist
RETURN .F.
ENDIF
*** No Error
RETURN .T.
ENDFUNC
* ttCustomer :: Validate
See also:
Class wwBusinessObject© West Wind Technologies, 1996-2024 • Updated: 11/09/18
Comment or report problem with topic