Conditional required business rule and UI prompting

Conditional required business rule and UI prompting

Old forum URL: forums.lhotka.net/forums/t/11532.aspx


hurcane posted on Friday, August 17, 2012

We have numerous instances of fields that are conditionally required based on the state of an object or based on properties of related entities. Typical examples: Customer PO is required on an order depending on a property of the related customer. Tracking number is required on shipment record depending on the selected carrier and customer. My order detail form has about a dozen of these conditionally required fields.

I have demonstrated in WinForms and WPF that the field can have an indicator when it is not filled in. The stakeholders are insisting that we display an asterisk on the field caption when it is required, even if it is filled in, and not violating the business rule. As the condition changes, they want the asterisk to automatically appear and disappear.

I am struggling with coming up with an elegant way to achieve this requirement.

My primary goals (maybe not realistic):

We have not decided on Winforms vs. WPF yet. I'm not averse to creating custom text box and drop-down controls or helper classes (something akin to the WPF PropertyInfo class, perhaps?).

I'm hoping somebody else has had similar requirements and could offer some suggestions.

Thanks!

JonnyBee replied on Saturday, August 18, 2012

As the rules is statically typed (per type) and only report the

That is really the limit.

Depending on how many "total combinations" you have - the only way that i can get this to work with the rule engine as-is is to use RuleSets.
RuleSets is the only solution in the RuleEngine to switch between complete sets of  rules and provide "metadate" for f.ex Required fields.
IE  - one complete ruleset for each condition per-type and use the "registered rules" in active ruleset to set the asterisk on the fields in the UI.

Not an ideal solution maybe by the only solution I can come up with using the RuleEnginge/model.

The last alternative would be to duplicate logic in the UI to set the asterisk.

And I wouldn't be surprised if this last alternative gives less clutter in the model and is easier to maintain. It may be more work to handle rulesets and keep the "active" ruleset updated based ogn values from other objects (intergraph references).

Peran replied on Sunday, August 19, 2012

Off the top of my head...

Could your business object contain 1 additional property being a collection of references to properties that are required. Your business rules could add/remove the property references within the collection as required.

WPF would use a property converter or custom binding to add/remove the asterisk from the caption, WinForms would probably need a control similar to PropertyInfo. 

 

Peran

hurcane replied on Monday, August 20, 2012

Peran,

As I thought about this problem over the weekend, I came up with a very similar answer. I like the idea of defining a collection for required fields. This does not introduce too much clutter, and we would make it part of our products base editable object.

I am thinking we might only put conditionally required fields in the collection. Business developers can use the "standard" attribute for fields that are always required. For conditional attributes, they can use a "gateway" rule that manipulates the collection and optionally executes a required rule when the condition is met. The gateway rule would have all of the criteria included as input properties, so it would be checked automatically and the collection would be updated as needed, without any extra code written by the business developer. This keeps the conditions in a single business rule.

The UI framework could then be developed to support both statically required field and conditionally required fields.

I am really liking the business rules system in CSLA 4.3 as compared to CSLA 3.0. While we have a lot of code to update in order to make this upgrade, it seems like it is going to simplify some of our most complex classes.

Thanks!

rfcdejong replied on Monday, August 20, 2012

Please take a look at my post where we solved simular problems by introducing a new kind of Rule  "ConditionRule"

http://forums.lhotka.net/forums/p/9699/45668.aspx

JonnyBee replied on Monday, August 20, 2012

The question from the original poster was more like 

* How can I get metadata about which fields is required for the object in this (object structure) state. 
  So that I can place an asterisk on ALL required fields and update as the state changes.

Not which rules is broken at this state or all registered rules and not how to write conditional rules.

I cannot se how that conditional rule will provide metadata as to whether the field is required or not?  

Copyright (c) Marimer LLC