Changes between Version 8 and Version 9 of QuickStart/4:HandlingaForm

Show
Ignore:
Timestamp:
12/02/09 15:42:10 (16 years ago)
Author:
DanWilson (IP: 71.77.43.34)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • QuickStart/4:HandlingaForm

    v8 v9  
    4040{{{ 
    4141<controller name="MyController" type="translator.controller.Controller"> 
    42     <message-listener message="OnRequestStart" function="OnRequestStart" /> 
    43     <message-listener message="OnRequestEnd" function="OnRequestEnd" /> 
     42    <message-listener message="OnRequestStart" /> 
     43    <message-listener message="OnRequestEnd" /> 
    4444    <message-listener message="NeedTranslation" function="TranslatePhrase" /> 
    4545</controller> 
    4646}}} 
     47 
     48(Note: If you do specify a function attribute, when the message is broadcast, it will call that specific function on the controller. If you do not specify a function attribute, Model-Glue will call a function named the same as the value of the message attribute.) 
    4749 
    4850Ok, now try the form. Again. 
     
    6870}}} 
    6971 
    70 (Note that in prior versions of the framework, the addTraceStatement() function was named trace(), but this was changed in order to support !ColdFusion 9, which was added a native trace() function to CFML.) 
     72(Note: that in prior versions of the framework, the addTraceStatement() function was named trace(), but this was changed in order to support !ColdFusion 9, which was added a native trace() function to CFML.) 
    7173 
    7274So what does all that do? 
    7375 
    74 First, arguments.event is like the twin sibling of the viewstate variable in a view. It has a getValue() method to get variables from the FORM and URL scopes. However, it also has a setValue() method that can set values into the viewstate, readable in views or later message listener functions. 
     76If you recall from the last segment, the event object has a getValue() method to get variables from the FORM and URL scopes. The Event object also has a setValue() method that can set values into the event, readable in views or later message listener functions. 
    7577 
    7678Second, it creates an instance of our application's Model CFC: 
     
    9597 
    9698{{{ 
    97 <cfset arguments.event.trace("TranslatePhrase Results", result) /> 
     99<cfset arguments.event.addTraceStatement("TranslatePhrase Results", result) /> 
    98100}}} 
    99101 
    100 Last, it sets the results of the translation into the viewstate so that our view templates can display the data: 
     102Last, it sets the results of the translation into the event object so that our view templates can display the data: 
    101103 
    102104{{{ 
     
    108110As a last step, let's add a view that shows our translated phrase. That'd probably make users happy, because we'll turn the debugging trace off when we deploy this application. 
    109111 
    110 Following the same steps as we did when we built the form, first add a dspPhrase.cfm file to /translator/views. You'll notice that we again use an eXit Event, this time to build a link back to the translation form. To the link, we append the "phrase" value. If you look back at frmPhrase.cfm, the VALUE attribute of our <cfinput> tag was set to viewstate.getValue("phrase"). getValue(), by default, returns an empty string if a value is not defined. By appending the phrase to the URL, we can set the default value of the input box. 
     112Following the same steps as we did when we built the form, first add a dspPhrase.cfm file to /translator/views. You'll notice that we again use an eXit Event, this time to build a link back to the translation form. To the link, we append the "phrase" value, using the second argument to the event.linkTo() method. If you look back at frmPhrase.cfm, the VALUE attribute of our <cfinput> tag was set to event.getValue("phrase"). getValue(), by default, returns an empty string if a value is not defined. By appending the phrase to the URL, we can set the default value of the input box. 
    111113 
    112114{{{ 
    113 <cfset translationForm = viewstate.getValue("myself") & viewstate.getValue("xe.translationForm") 
    114     & "&phrase=" & viewstate.getValue("phrase") /> 
    115 <cfset translatedPhrase = viewstate.getValue("translatedPhrase") /> 
     115<cfset translationForm = event.linkTo( event.getValue("xe.translationForm"), "phrase" ) /> 
     116<cfset translatedPhrase = event.getValue("translatedPhrase") /> 
    116117 
    117118<cfoutput>