How to check custom properties?

I played with the nhibernate validator and got an almost perfect solution.

I can determine the property to be checked, and it runs when pre-saved. But I have cases when it does not work.

Suppose I have an object called a person, and through nhibernate I matched an address (also an object) as a property of a person (this is actually a list of addresses).

When I save a person, my address is not verified.

The form for entering information is formed from partial forms. It would be nice if the address verification could be added to the identity verification list, but this is not required.

I need a general solution, I can’t confirm it with a β€œhand”, for example. if the person then checks the address ... Somehow the validator should see that there is an object behind the property, which I also need to check.

Update: what I'm looking for is a way to check the displayed objects (hasmany).

+4
source share
2 answers

After upgrading to the latest release of nhibernate validator, validation works for subclasses and associated classes. Together with xVal 1.0, this is a very satisfactory solution.

Now I can determine for each property that it should be checked (for example, for regular expression, length, etc.), and I get a message on the client side through xVal on the server side through nHibernate Validator. In fact, they use a validation pattern and error messages.

I would recommend this for any nHibernate-Project where a simple definition is required for validation and messaging.

+1
source

If you are trying to enter confirmation of the input in these classes, which I think you are trying to do, I would advise you to do this, since this is business logic. Everything you find in Hibernate that does this does this only to ensure that the database is constrained (i.e., a non-zero Column).

I would recommend that you create a utility class or method to validate input. If you need to add database constraints to the properties of an entity, be sure to do this, but I will not rely on them to validate the input.

+1
source

All Articles