| Version 2 (modified by cfgrok, 17 years ago) |
|---|
Using modelglue.GenericList
When this message is broadcast, the DataController will attempt to list records from a given table.
This message is configured by using the following <argument> tags:
- Object (Required) - The name of the table to list.
- QueryName (Optional) - The name of the viewstate value to set the resultant query into. Defaults to Object & "Query".
- 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.
- OrderBy (Optional) - A single column name by which to order the query.
- Ascending (Optional) - If set to true, order will be ascending. If set to false, order will be descending.
Examples
A Basic Generic List
To perform a basic list on a Contact table, the following <message> tag could be added to an <event-handler>:
<message name="modelglue.GenericList">
<argument name="object" value="Contact" />
</message>
A View could then <cfdump> the query by performing the following code:
<cfdump var="#viewstate.getValue("ContactQuery")#" />
Customizing the Viewstate value name
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>:
<message name="modelglue.GenericList">
<argument name="object" value="Contact" />
<argument name="queryName" value="aListOfContacts" />
</message>
A View could then <cfdump> the query by performing the following code:
<cfdump var="#viewstate.getValue("aListOfContacts")#" />
Applying a Filter
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>:
<message name="modelglue.GenericList">
<argument name="object" value="Contact" />
<argument name="criteria" value="Firstname" />
</message>
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:
index.cfm?event=contact.list&firstname=Fred
Ordering
To perform a basic list on a Contact table ordered by Lastname (ascending), the following <message> tag could be added to an <event-handler>:
<message name="modelglue.GenericList">
<argument name="object" value="Contact" />
<argument name="orderBy" value="Lastname" />
</message>
To reverse the order, the following argument tag could be added:
<argument name="ascending" value="false" />
A View could then <cfdump> the query by performing the following code:
<cfdump var="#viewstate.getValue("ContactQuery")#" />
![(please configure the [header_logo] section in trac.ini)](/ModelGlue.com/trac.cgi/chrome/site/your_project_logo.png)