Changes between Version 8 and Version 9 of QuickStart/4:HandlingaForm
- Timestamp:
- 12/02/09 15:42:10 (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
QuickStart/4:HandlingaForm
v8 v9 40 40 {{{ 41 41 <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" /> 44 44 <message-listener message="NeedTranslation" function="TranslatePhrase" /> 45 45 </controller> 46 46 }}} 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.) 47 49 48 50 Ok, now try the form. Again. … … 68 70 }}} 69 71 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.) 71 73 72 74 So what does all that do? 73 75 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.76 If 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. 75 77 76 78 Second, it creates an instance of our application's Model CFC: … … 95 97 96 98 {{{ 97 <cfset arguments.event. trace("TranslatePhrase Results", result) />99 <cfset arguments.event.addTraceStatement("TranslatePhrase Results", result) /> 98 100 }}} 99 101 100 Last, it sets the results of the translation into the viewstateso that our view templates can display the data:102 Last, it sets the results of the translation into the event object so that our view templates can display the data: 101 103 102 104 {{{ … … 108 110 As 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. 109 111 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.112 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, 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. 111 113 112 114 {{{ 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") /> 116 117 117 118 <cfoutput>
![(please configure the [header_logo] section in trac.ini)](/ModelGlue.com/trac.cgi/chrome/site/your_project_logo.png)