| | 1 | = Using modelglue.!GenericList = |
| | 2 | |
| | 3 | When this message is broadcast, the !DataController will attempt to list records from a given table. |
| | 4 | |
| | 5 | This message is configured by using the following <argument> tags: |
| | 6 | |
| | 7 | 1. Object (Required) - The name of the table to list. |
| | 8 | 1. !QueryName (Optional) - The name of the viewstate value to set the resultant query into. Defaults to Object & "Query". |
| | 9 | 1. Criteria (Optional) - A list of viewstate values to use as filters. Any value listed whose name matches a column in the target table will be used as a filter in the query's WHERE clause. |
| | 10 | 1. !OrderBy (Optional) - A single column name by which to order the query. |
| | 11 | 1. Ascending (Optional) - If set to true, order will be ascending. If set to false, order will be descending. |
| | 12 | |
| | 13 | == Examples == |
| | 14 | |
| | 15 | === A Basic Generic List === |
| | 16 | |
| | 17 | To perform a basic list on a Contact table, the following <message> tag could be added to an <event-handler>: |
| | 18 | |
| | 19 | {{{ |
| | 20 | <message name="modelglue.GenericList"> |
| | 21 | |
| | 22 | <argument name="object" value="Contact" /> |
| | 23 | |
| | 24 | </message> |
| | 25 | }}} |
| | 26 | |
| | 27 | A View could then <cfdump> the query by performing the following code: |
| | 28 | |
| | 29 | {{{ |
| | 30 | <cfdump var="#viewstate.getValue("ContactQuery") /> |
| | 31 | }}} |
| | 32 | |
| | 33 | === Customizing the Viewstate value name === |
| | 34 | |
| | 35 | To perform a basic list on a Contact table and set it into a specific value in the Viewstate, the following <message> tag could be added to an <event-handler>: |
| | 36 | |
| | 37 | {{{ |
| | 38 | <message name="modelglue.GenericList"> |
| | 39 | |
| | 40 | <argument name="object" value="Contact" /> |
| | 41 | |
| | 42 | <argument name="queryName" value="aListOfContacts" /> |
| | 43 | |
| | 44 | </message> |
| | 45 | }}} |
| | 46 | |
| | 47 | A View could then <cfdump> the query by performing the following code: |
| | 48 | |
| | 49 | {{{ |
| | 50 | <cfdump var="#viewstate.getValue("aListOfContacts") /> |
| | 51 | }}} |
| | 52 | |
| | 53 | === Applying a Filter === |
| | 54 | |
| | 55 | To perform a basic list on a Contact table that would filter on the viewstate's current Firstname value, the following <message> tag could be added to an <event-handler>: |
| | 56 | |
| | 57 | {{{ |
| | 58 | <message name="modelglue.GenericList"> |
| | 59 | |
| | 60 | <argument name="object" value="Contact" /> |
| | 61 | |
| | 62 | <argument name="criteria" value="Firstname" /> |
| | 63 | |
| | 64 | </message> |
| | 65 | }}} |
| | 66 | |
| | 67 | Assuming an event-handler name of "contact.list", visiting the event handler with the following URL would result in only contacts with a Firstname of "Fred" being selected: |
| | 68 | |
| | 69 | index.cfm?event=contact.list&firstname=Fred |
| | 70 | |
| | 71 | === Ordering === |
| | 72 | |
| | 73 | To perform a basic list on a Contact table ordered by Lastname (ascending), the following <message> tag could be added to an <event-handler>: |
| | 74 | |
| | 75 | {{{ |
| | 76 | <message name="modelglue.GenericList"> |
| | 77 | |
| | 78 | <argument name="object" value="Contact" /> |
| | 79 | |
| | 80 | <argument name="orderBy" value="Lastname" /> |
| | 81 | |
| | 82 | </message> |
| | 83 | }}} |
| | 84 | |
| | 85 | To reverse the order, the following argument tag could be added: |
| | 86 | |
| | 87 | {{{ |
| | 88 | <argument name="ascending" value="false" /> |
| | 89 | }}} |
| | 90 | |
| | 91 | A View could then <cfdump> the query by performing the following code: |
| | 92 | |
| | 93 | {{{ |
| | 94 | <cfdump var="#viewstate.getValue("ContactQuery") /> |