Hello all,

I'm trying to use the ValidateIsUnique attribute on my models, and
then use the ARDataBinder in my controllers, and I'm having trouble
with the HasValidationError method not catching invalid properties.
Here is the code I'm using:
Controller:
        public void Update([ARDataBind("performer", AutoLoad =
AutoLoadBehavior.Always, Validate = true)] CatalogPerformer performer)
{
                        if (HasValidationError(performer)) {
                                Logger.Warn("Has error from validator");
                Flash["performer"] = performer;
                Flash["summary"] = GetErrorSummary(performer);
                RedirectToReferrer();
                return;
            }

            try {
                // Save performer
                performer.Save();
                Flash["message"] = "Performer changes saved";
                RedirectToAction("list");
                        } catch (Exception ex) {
                Flash["message"] = ex.Message;
                Flash["performer"] = performer;

                RedirectToReferrer();
            }
        }

And here is the applicable part of the model:

        [ActiveRecord("catalog_performers", Lazy = true)]
        public class CatalogPerformer :
ActiveRecordValidationBase<CatalogPerformer> {
                private string name;
                private int id;

        [PrimaryKey("id")]
                public virtual int Id {
                        get { return id; }
                        set { id = value; }
                }

                [Property("name", Index="performerNameIndex")]
                [ValidateIsUnique("A performer with that name already exists, 
please
choose another")]
        [ValidateNonEmpty("Please enter a name")]
                public virtual string Name {
                        get { return name; }
                        set { name = value; }
                }
}

When the HasValidationError method runs in the Update method, it
returns false even if ValidateIsUnique has failed.  After searching
through some code, I believe it's due to the IsUnique validator being
part of Castle.Activerecord, while the rest of the validators are in
the Castle.Components.Validator namespace.  I know that the IsUnique
validator must work differently since it has to query the domain first
before validating, but is there a way to get the HasValidationError
and GetErrorSummary methods to recognize this attribute as well as the
others?

Currently the only solution I've found is to use a separate block to
catch errors using the IsValid method, and the ValidationErrorMessages
property on performer.  Any ideas are appreciated.

Thanks!
Brian

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to