Changes between Initial Version and Version 1 of HowTos/HowToUseGenericDatabaseMessages/UsingmodelglueGenericCommit

Show
Ignore:
Timestamp:
04/15/09 19:43:28 (17 years ago)
Author:
trac (IP: 127.0.0.1)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • HowTos/HowToUseGenericDatabaseMessages/UsingmodelglueGenericCommit

    v1 v1  
     1= Using modelglue.!GenericCommit = 
     2 
     3When this message is broadcast, the !DataController will attempt to save a record to a given table. 
     4 
     5It performs this action by doing the following: 
     6 
     7  1. Loading an existing record to perform updates, or creating a new record to insert of none matches the criteria specified. 
     8  1. Updating the record's field values. By default, any field with a corresponding value in the viewstate (the combination of FORM and URL scopes) will be set to the value in the viewstate.[[BR]][[BR]] This means that for a given contact, the value of a form input named "firstname" will automatically populate the Firstname property of a contact record.[[BR]][[BR]] By default, the !DataController will attempt to populate all fields from any like-named values in the viewstate. To control which properties to populate, use the "properties" argument as documented below. 
     9  1. Validating the record by calling its Validate() method. 
     10  1. If the record is valid, the !DataController will save its data to the database 
     11  1. Last, the !DataController adds one of two results: "commit" or "validationError". '''Adding result mappings for these result names works in the same manner as any other result mapping.''' 
     12 
     13This message is configured by using the following <argument> tags: 
     14 
     15  1. Object (Required) - The name of the table to which to commit a record. 
     16  1. Criteria (Required) - 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. This will most often be set to a list of the table's primary keys. If left empty, a new record will be created. If a given record matches the criteria specified, the record will be updated. Otherwise, a new record will be inserted. 
     17  1. !RecordName (Optional) - The name of the viewstate value to set the resultant record into. Defaults to Object & "Record". 
     18  1. !ValidationName (Optional) - The name of the viewstate value to set a collection of validation errors into. Defaults to Object & "Validation". 
     19  1. Properties (Optional) - The names of the Record's fields to attempt to populate from like-named values in the viewstate. Defaults to all of the record's fields. 
     20 
     21== Examples == 
     22 
     23=== A Basic Generic Commit === 
     24 
     25To perform a basic commit on the Contact table, the following <message> tag could be added to an <event-handler>: 
     26 
     27{{{ 
     28<message name="modelglue.GenericCommit"> 
     29 
     30<argument name="object" value="Contact" /> 
     31 
     32<argument name="contactId" value="Contact" /> 
     33 
     34</message> 
     35}}} 
     36 
     37A View could then <cfdump> the record by performing the following code: 
     38 
     39{{{ 
     40<cfdump var="#viewstate.getValue("ContactRecord") /> 
     41}}} 
     42 
     43A View could then <cfdump> any validation messages by performing the following code: 
     44 
     45{{{ 
     46<cfdump var="#viewstate.getValue("ContactValidation") /> 
     47}}} 
     48 
     49Assuming an event-handler name of "contact.commit", visiting the event handler with the following URL would result in updating !ContactId 42's first name to "Fred". 
     50 
     51index.cfm?event=contact.commit&contactId=42&firstname=Fred 
     52 
     53=== Customizing the Viewstate value name === 
     54 
     55To perform a basic commit on the Contact table and specify viewstate value names for both the record and its validation, the following <message> tag could be added to an <event-handler>: 
     56 
     57{{{ 
     58<message name="modelglue.GenericCommit"> 
     59 
     60<argument name="object" value="Contact" /> 
     61 
     62<argument name="contactId" value="Contact" /> 
     63 
     64<argument name="recordName" value="myCommittedContact" /> 
     65 
     66<argument name="validationName" value="validationForContact" /> 
     67 
     68</message> 
     69}}} 
     70 
     71A View could then <cfdump> the record by performing the following code: 
     72 
     73{{{ 
     74<cfdump var="#viewstate.getValue("myCommittedContact") /> 
     75}}} 
     76 
     77A View could then <cfdump> any validation messages by performing the following code: 
     78 
     79{{{ 
     80<cfdump var="#viewstate.getValue("validationForContact") /> 
     81}}} 
     82 
     83Assuming an event-handler name of "contact.commit", visiting the event handler with the following URL would result in updating !ContactId 42's first name to "Fred". 
     84 
     85index.cfm?event=contact.commit&contactId=42&firstname=Fred 
     86 
     87=== Committing Specific Properties === 
     88 
     89To perform a basic commit on the Contact table where only the Firstname would be updated, the following <message> tag could be added to an <event-handler>: 
     90 
     91{{{ 
     92<message name="modelglue.GenericCommit"> 
     93 
     94<argument name="object" value="Contact" /> 
     95 
     96<argument name="contactId" value="Contact" /> 
     97 
     98<argument name="properties" value="Firstname" /> 
     99 
     100</message> 
     101}}} 
     102 
     103A View could then <cfdump> the record by performing the following code: 
     104 
     105{{{ 
     106<cfdump var="#viewstate.getValue("ContactRecord") /> 
     107}}} 
     108 
     109A View could then <cfdump> any validation messages by performing the following code: 
     110 
     111{{{ 
     112<cfdump var="#viewstate.getValue("ContactValidation") /> 
     113}}} 
     114 
     115Assuming an event-handler name of "contact.commit", visiting the event handler with the following URL would result in updating !ContactId 42's first name to "Fred" but '''not''' updating the lastname to "Finklebuster" 
     116 
     117index.cfm?event=contact.commit&contactId=42&firstname=Fred&lastname=Finklebuster