# 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:

1. Object (Required) - The name of the table to list.

2. QueryName (Optional) - The name of the viewstate value to set the resultant query into. Defaults to Object & "Query".

3. 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.

4. OrderBy (Optional) - A single column name by which to order the query.

5. 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")#" />