Search This Blog

Thursday, June 26, 2014

ViewController or Action activation for multiple Views or target object types via the TargetViewId property

I would like to highlight a small usability improvement that may help you write less and simpler code when configuring a target View for which a ViewController or an Action will be available.

Let's consider a couple scenarios where it may be helpful:
1. Your ViewController/Action should work for Views corresponding to absolutely unrelated Object1 and Object2 types (there is no inheritance between them and they are not descended from a common base class).
2. Your ViewController/Action should work for several specific Views of a certain object type, but be unavailable for other Views of the same type (e.g., be active for Object3_ListView, Object3_DetailView, but not for Object3_LookupListView and others).

Starting with version 14.1, you can implement the second scenario by setting the TargetViewId property of your ViewController or Action by providing a semicolon-separated list of Views, for which your element should be activated. Previously, you should have written the View.Id checks manually before executing your code. Please consider the following example:

I remember first implementing this functionality for ConditionalAppearance rules, which you might already use, so I hope you will welcome this addition as well.

As for the first scenario, you can also accomplish it with the improved TargetViewId property by listing all required Views there. However, there may be a lot of Views, including custom ones, and it is possible that in this particular case, you would be better off with a solution which was always available in our framework. This implies settings the TargetObjectType property to the interface type, which is implemented by required object types. I suggest you check out the How to implement a controller that will work for more than one target object type article if you did not know about that option.

I hope you find this new trick helpful for your XAF kung fu arsenal:-)

1 comment:

  1. The Ultimate Business Application Framework

    Business platform Xafari is intended for development of powerful business-oriented applications. It uses state of the art flexible platform DevExpress XAF http://galaktikasoft.com/xafari/

    ReplyDelete