v
Not logged inv
ForumsBlogs
Blogs

Gary's Blog

> All Tags

XAF – RuleCriteria and Read Only Properties

     

As a man I never read the instructions; it’s baked into our DNA. There were no instruction manuals back when we lived in caves, right? So if we didn’t need them then, we sure as heck don’t need them now. This applies doubly so when I’m working with XAF. Why? Two reason really. Firstly, it allows me to see how intuitive XAF is – does it work, out of the box, the way I naturally think it should? Secondly, when I get stuck, it allows me to see how easy it is to get unstuck using our documentation. (okay when I said I never read instructions, I meant never *before* the fact.)

Right now I’m working on an XAF application (more on that later) and I want to set up some validation rules; specifically I want to validate that a StartDate is greater than or equal to today’s date. So, naturally, I intuitively I write:

[RuleCriteria("StartDateMustBeAfterToday", DefaultContexts.Save, "StartDate >= DateTime.Now.Date")]

Which doesn’t work and throws this error:

image

Well okay, so much for intuition, time to find out how it should really be done. So, I open the documentation page for RuleCriteria and I read it; and it’s right there, you saw it didn’t you? No? Meh, me neither first time round. It’s there in the “Remarks” section.

“In criteria, you can use Read-Only Parameters. For instance, the "Today = '@CurrentDate'" criterion means that the Today property must be set to the current date.”

That single sentence, tucked away in the remarks section is important, hence my post today. It means two things. One, that my code should have be written as:

[RuleCriteria("StartDateMustBeAfterToday", DefaultContexts.Save, "StartDate >= '@CurrentDate'")]

Which will throw the following validation error, as required:

image

It also means that all the read-only parameters, which we document as being used for filtering (which is true) can also be used in RuleCriteria, so go check them out and have fun!

Published Jun 25 2009, 10:56 AM by Gary Short (DevExpress)  
Filed under:
Technorati tags: XAF

Comments

 

Alex Hoffman said:

"As a man I never read the instructions; it’s baked into our DNA. There were no instruction manuals back when we lived in caves, right? So if we didn’t need them then, we sure as heck don’t need them now."

LOL - I just emailed that to my wife!

June 25, 2009 6:05 AM
 

Rachel Hawley (DevExpress) said:

*Sigh* men and destructions .... sorry, I mean INstructions. Mind you, I was probably closer the first time :-)

June 25, 2009 7:24 AM
 

Gary Short (DevExpress) said:

Says the girl who recently put her new office chair together with a hammer. :-P

June 25, 2009 8:34 AM