Changes between Version 9 and Version 10 of QuickStart/4:HandlingaForm
- Timestamp:
- 12/21/09 21:08:10 (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
QuickStart/4:HandlingaForm
v9 v10 39 39 40 40 {{{ 41 <controller name="MyController" type="translator.controller.Controller"> 42 <message-listener message="OnRequestStart" /> 43 <message-listener message="OnRequestEnd" /> 41 <controller name="Controller" type="translator.controller.Controller"> 44 42 <message-listener message="NeedTranslation" function="TranslatePhrase" /> 45 43 </controller> … … 48 46 (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.) 49 47 50 O k, now try the form. Again.48 OK, now try the form. Again. 51 49 52 Still nothing? There's one last piece to the puzzle: write a !TranslatePhrase function in the Controller that asks our Model to translate a phrase! That's easy enough - just open /translator/controller/Controller.cfc and add the following <cffunction>: 50 This time you will encounter an error: "The method !TranslatePhrase was not found in component [your file system path]Controller.cfc" 51 52 There's one last piece to the puzzle: write a !TranslatePhrase function in the Controller that asks our Model to translate a phrase! That's easy enough - just open /translator/controller/Controller.cfc and add the following <cffunction>: 53 53 54 54 {{{ … … 60 60 <cfset var result = translator.translate(phrase) /> 61 61 62 <cfset arguments.event.addTraceStatement(" TranslatePhrase Results", result) />62 <cfset arguments.event.addTraceStatement("User", "TranslatePhrase Results", result) /> 63 63 <cfset arguments.event.setValue("translatedPhrase", result) /> 64 64 </cffunction> 65 66 <cffunction name="OnRequestStart" access="public" returntype="void" output="false"></cffunction>67 68 <cffunction name="OnRequestEnd" access="public" returntype="void" output="false"></cffunction>69 70 65 }}} 71 66 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 wasadded a native trace() function to CFML.)67 (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 added a native trace() function to CFML.) 73 68 74 69 So what does all that do? … … 97 92 98 93 {{{ 99 <cfset arguments.event.addTraceStatement(" TranslatePhrase Results", result) />94 <cfset arguments.event.addTraceStatement("User", "TranslatePhrase Results", result) /> 100 95 }}} 101 96 … … 106 101 }}} 107 102 108 O k, finally, run the form! Seriously, something will happen this time! You won't get much, but you'll see a line in the Model-Glue debugging trace labelled"!TranslatePhrase Results" that shows the translated phrase.103 OK, finally, run the form! Seriously, something will happen this time! You won't get much, but you'll see a row in the Model-Glue debugging trace with the message "!TranslatePhrase Results" that shows the translated phrase. 109 104 110 105 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. … … 113 108 114 109 {{{ 115 <cfset translationForm = event.linkTo( event.getValue("xe .translationForm"), "phrase" ) />110 <cfset translationForm = event.linkTo( event.getValue("xe_translationForm"), "phrase" ) /> 116 111 <cfset translatedPhrase = event.getValue("translatedPhrase") /> 117 112 … … 131 126 <views> 132 127 <include name="body" template="dspPhrase.cfm"> 133 <value name="xe .translationForm" value="translationForm" />128 <value name="xe_translationForm" value="translationForm" /> 134 129 </include> 135 130 </views> … … 141 136 ---- 142 137 143 Back [wiki:QuickStart/3:BuildingaForm #Quickstart3:BuildingaFormEventQuickstart 3: Building a Form Event]138 Back [wiki:QuickStart/3:BuildingaForm Quickstart 3: Building a Form Event] 144 139 145 Next [wiki:QuickStart/5:ValidatingaForm #Quickstart5:ValidatingaFormQuickstart 5: Validating a Form]140 Next [wiki:QuickStart/5:ValidatingaForm Quickstart 5: Validating a Form] 146 141
![(please configure the [header_logo] section in trac.ini)](/ModelGlue.com/trac.cgi/chrome/site/your_project_logo.png)