1
Answer

Conditional validation of fields in a Class

Kasper Tito

Kasper Tito

16y
4.4k
1

Hi
I would like to perform some conditional validation on fields in a class and am not sure of the best way to do this.
These fields can be mandatory or optional depending on whether other fields (in the class) are set.
 
Here, I have a method which has an input parameter which is of type CQuery (a class):

response = ProcessQuery(CQuery)

I would like to validate this parameter and check that all required fields are set correctly.

Here are the fields in class CQuery:

Tenancy  - this can be either Freehold or Leasehold
LengthOfLease - req' if Tenancy is Leasehold..
Landlord - req'd if Tenancy is Leasehold
PropertyValue - req'd if Tenancy is freehold.

The value for Tenancy, dictates which other field are mandatory or optional.

Is there a good way to do this without resorting to nested If else, If else, if else etc.. ?
I have other classes which are more complex and these would require some complex validation rules...and have many fields..
I have thought about serialising the class to XML at runtime and then perhaps validating the XML against a schema, but am not sure if this is the best way.
I have also considered using reflection, but then would still require some way to apply the validation rules.

thank you in advance!

Answers (1)
0
Zoran Horvat

Zoran Horvat

NA 5.7k 516.3k 13y
You can create framed Web page. Then in the frame which should depict the latest feed contents you load HTML which automatically reloads every, say, 30-60 seconds (don't do it more often unless you're absolutely sure that client can refresh contents in time much shorter than 1 second anywhere in the world).

Make sure that this HTML is small and loads very quickly or otherwise users will have discomfort looking at the page which spends significant time in incomplete state.

If you can't load it quickly then make a background process which does the heavy job processing latest feed state, and simply creates fixed HTML which would then quickly be presented to users on every reload.

Zoran
Accepted
0
Jiteendra Sampathirao

Jiteendra Sampathirao

NA 6.9k 1.5m 13y

Hi,
use AJAX to refresh the specific part of the page.........


Next Recommended Forum