-
Notifications
You must be signed in to change notification settings - Fork 3
Dynamic attributes
Some tasks can have dynamic attributes. This means that the actual value of the attribute is determined at runtime, based on the variables present on the event object.
An attribute becomes dynamic if you prefix it with a percentage sign (%):
<dispatch target="%dynamicTarget" event="%dynamicEvent" />
The variables dynamicTarget and dynamicEvent are expected to exist on the event object, otherwise an exception is thrown.
Following the percentage sign, any ColdFusion expression may follow, for instance:
<set nextEvent="%loggedin ? 'home' : 'login'" />
<redirect event="%nextEvent" />
Just make sure that the expression doesn't invalidate the XML document.
You can use functions:
<set userCount="%ArrayLen(users)" />
<set fullname="%bean.getFirstName() & ' ' & bean.getLastName()">
Use %% to escape evaluation.
Whether you should use dynamic attributes or not is a matter of taste. You probably shouldn't use them extensively, and in limited cases. Things like putting the user count on the event should be done by a controller, not in the configuration. However, one of the aims of CFlow is to keep the handlers in the controllers reusable (see reasons), which means, among other things, that they shouldn't have to know where to go to next, for instance. Using dynamic attributes, combined with <if> and <else> moves all knowledge of application flow out of the controllers.