| | 1 | [[PageOutline]] |
| | 2 | |
| | 3 | = Event API = |
| | 4 | |
| | 5 | When a function in a controller is called as a result of a <message-listener> tag, it is passed an instance of the !ModelGlue.unity.eventrequest.!EventContext CFC. |
| | 6 | |
| | 7 | This CFC contains a series of functions known as the Event API that are useful to getting and setting values in the viewstate as well as event-related utilities. |
| | 8 | |
| | 9 | == !AddResult(name:string) == |
| | 10 | |
| | 11 | Adds a result by the given name. If a <result> tag exists in the currently executing <event-handler> whose NAME attribute matches the value passed, the <event-handler> declared in its DO attribute will be added to the request. |
| | 12 | |
| | 13 | ==== Returns: ==== |
| | 14 | |
| | 15 | Void |
| | 16 | |
| | 17 | ==== Arguments: ==== |
| | 18 | |
| | 19 | Name (Required) - The name of the result to add |
| | 20 | |
| | 21 | == !ArgumentExists(string:name) == |
| | 22 | |
| | 23 | ==== Description: ==== |
| | 24 | |
| | 25 | Does a value of the given name exist in the current message tag's arguments block? |
| | 26 | |
| | 27 | ==== Returns: ==== |
| | 28 | |
| | 29 | Boolean |
| | 30 | |
| | 31 | ==== Arguments: ==== |
| | 32 | |
| | 33 | Name (required) - The name of the argument to check |
| | 34 | |
| | 35 | == Forward(eventhandler:string [, append:list]) == |
| | 36 | |
| | 37 | ==== Description: ==== |
| | 38 | |
| | 39 | Immediately redirects the request to the event handler named. All values in the viewstate are maintained across the redirect if session is enabled. |
| | 40 | |
| | 41 | ==== Returns: ==== |
| | 42 | |
| | 43 | Void. The function call never completes - a <cflocation> interrupts its execution. |
| | 44 | |
| | 45 | ==== Arguments: ==== |
| | 46 | |
| | 47 | !EventHandler (Required) - The name of the event handler to redirect to |
| | 48 | |
| | 49 | Append (Optional) - Will append the list of values passed in append to the resultant URL. |
| | 50 | |
| | 51 | ==== Example: ==== |
| | 52 | |
| | 53 | {{{ |
| | 54 | <!--- Results in a url with a query string of ?event=article.view&articleId=2 ---> |
| | 55 | |
| | 56 | <cfset arguments.event.setValue("articleId", 2) /> |
| | 57 | |
| | 58 | <cfset arguments.event.forward("article.view", "articleId") /> |
| | 59 | }}} |
| | 60 | |
| | 61 | == !GetAllArguments() == |
| | 62 | |
| | 63 | ==== Description: ==== |
| | 64 | |
| | 65 | Returns the structure that contains all argument members ''by reference''. |
| | 66 | |
| | 67 | ==== Returns: ==== |
| | 68 | |
| | 69 | Struct |
| | 70 | |
| | 71 | ==== Arguments: ==== |
| | 72 | |
| | 73 | None |
| | 74 | |
| | 75 | == !GetAllValues() == |
| | 76 | |
| | 77 | ==== Description: ==== |
| | 78 | |
| | 79 | Returns the structure that contains all viewstate members ''by reference''. |
| | 80 | |
| | 81 | ==== Returns: ==== |
| | 82 | |
| | 83 | Struct |
| | 84 | |
| | 85 | ==== Arguments: ==== |
| | 86 | |
| | 87 | None |
| | 88 | |
| | 89 | == !GetArgument(name:string [, default:any]) == |
| | 90 | |
| | 91 | ==== Description: ==== |
| | 92 | |
| | 93 | Returns a value from the current message tag's arguments block. |
| | 94 | |
| | 95 | ==== Returns: ==== |
| | 96 | |
| | 97 | Any |
| | 98 | |
| | 99 | ==== Arguments: ==== |
| | 100 | |
| | 101 | Name (required) - The name of the argument to retrieve |
| | 102 | |
| | 103 | Default (optional) - If the argument does not exist, a default value to return. It is ''not'' set into the argument collection - the collection is read-only. |
| | 104 | |
| | 105 | ==== Example: ==== |
| | 106 | |
| | 107 | {{{ |
| | 108 | <!-- ModelGlue.xml ---> |
| | 109 | |
| | 110 | <event-handler name="argumentExample"> |
| | 111 | |
| | 112 | <broadcasts> |
| | 113 | |
| | 114 | <message name="example"> |
| | 115 | |
| | 116 | <argument name="someArgument" value="someValue" /> |
| | 117 | |
| | 118 | </message> |
| | 119 | |
| | 120 | </broadcasts> |
| | 121 | |
| | 122 | </event-handler> |
| | 123 | |
| | 124 | <!--- In a message listener function ---> |
| | 125 | |
| | 126 | <cfset var argumentValue = arguments.event.getArgument("someArgument") /> |
| | 127 | }}} |
| | 128 | |
| | 129 | == !GetValue(name:string [, default:any]) == |
| | 130 | |
| | 131 | ==== Description: ==== |
| | 132 | |
| | 133 | Returns a value from the viewstate, such as a form or url variable. |
| | 134 | |
| | 135 | ==== Returns: ==== |
| | 136 | |
| | 137 | Any |
| | 138 | |
| | 139 | ==== Arguments: ==== |
| | 140 | |
| | 141 | Name (required) - The name of the value to retrieve |
| | 142 | |
| | 143 | Default (optional) - If the value does not exist, a default value to set into the viewstate and then return |
| | 144 | |
| | 145 | == !GetView(name:string) == |
| | 146 | |
| | 147 | ==== Description: ==== |
| | 148 | |
| | 149 | Returns the rendered content of a view. |
| | 150 | |
| | 151 | ==== Returns: ==== |
| | 152 | |
| | 153 | String |
| | 154 | |
| | 155 | ==== Arguments: ==== |
| | 156 | |
| | 157 | Name (required) - The name of the view to retrieve |
| | 158 | |
| | 159 | == !MakeEventBean(type:any, [fields:list]) == |
| | 160 | |
| | 161 | ==== Description: ==== |
| | 162 | |
| | 163 | Loops over a CFC instance, looking for any methods whose names start with set. For any setter methods where a like-named value exists in the viewstate, the setter will be called, passing this value. |
| | 164 | |
| | 165 | ==== Returns: ==== |
| | 166 | |
| | 167 | CFC Instance |
| | 168 | |
| | 169 | ==== Arguments: ==== |
| | 170 | |
| | 171 | Type (Required) - If a string is passed, it will instantiate a CFC of the type passed and attempt to call a function named "init" if one exists. If a CFC instance is passed, it will use the instance. |
| | 172 | |
| | 173 | Fields (Optional) - If a list of fields is passed, it will only attempt to set the properties listed. |
| | 174 | |
| | 175 | == Trace(name:string, value:any) == |
| | 176 | |
| | 177 | ==== Description: ==== |
| | 178 | |
| | 179 | Adds the value to the debugging trace and gives it the name passed. If a complex value is passed, the result of its <cfdump> is displayed. |
| | 180 | |
| | 181 | ==== Returns: ==== |
| | 182 | |
| | 183 | Void |
| | 184 | |
| | 185 | ==== Arguments: ==== |
| | 186 | |
| | 187 | Name (Required) - A label to identify the value in the debugging trace |
| | 188 | |
| | 189 | Value (Required) - The value to display in the debugging trace. If a complex value is passed, the result of its <cfdump> is displayed. |
| | 190 | |
| | 191 | == !ValueExists(string:name) == |
| | 192 | |
| | 193 | ==== Description: ==== |
| | 194 | |
| | 195 | Does a value of the given name exist in the viewstate? |
| | 196 | |
| | 197 | ==== Returns: ==== |
| | 198 | |
| | 199 | Boolean |
| | 200 | |
| | 201 | ==== Arguments: ==== |
| | 202 | |
| | 203 | Name (required) - The name of the value to check |