Ticket #337 (closed defect: fixed)
copyToScope() default array values overwrite event values
| Reported by: | Jamie Krug | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.0 |
| Version: | 3.0.178 | Severity: | minor |
| Keywords: | Cc: |
Description (last modified by cfgrok) (diff)
Originally posted by Jamie Krug on 1/9/2009 at 1:26 PM: entered by Ezra Parker on port to new system
Environment: ModelGlue 3/Gesture svn rev 115 (latest ber as of 1/9/08), ColdFusion 8 developer edition, Ubuntu 8.04
When using the third, optional, argument (array of default values) to the event.copyToScope() method in a view, I find that any default values specified will take precedence over a value already in the event (e.g., specified in the query string).
For example, using the sample code provided at http://www.model-glue.com/blog/index.cfm/2008/9/9/New-Model-Glue-3-Feature-copyToScope ...
<cfset defaultArray = ["DefaultForFoot", "DefaultForHand"] /> <cfset event.copyToScope(variables, "foot,hand,xe.nested", defaultArray) />
This works as expected when no values exist in the event for the keys specified, but not when one of those values already exists in the event. For example, if the above code was in a view called by event=my.event, I'd expect this URL call...
http://localhost/index.cfm?event=my.event&foot=MyFootValue
...to produce these values in the variables scope:
foot = 'MyFootValue' hand = 'DefaultForHand' xe.nested = ''
Unfortunately, it is still setting variables.foot = 'DefaultForFoot' instead of the value specified in the query string.
If I change the view to use the "old fashioned" way, it works as expected, with:
foot = event.getValue('foot', 'DefaultForFoot');
hand = event.getValue('hand', 'DefaultForHand');
xe.nested = event.getValue('xe.nested');
I'm assuming I'm correct to expect copyToScope() to behave much like the above when defaults are specified, right?
If so, then I believe the following patch is the fix (for http://svn.firemoss.com/modelglue/trunk/ModelGlue/gesture/eventrequest/EventContext.cfc@115)
Thanks in advance Model-Glue Team!
Note: inline patches not included due to superceding attachments.
![(please configure the [header_logo] section in trac.ini)](/ModelGlue.com/trac.cgi/chrome/site/your_project_logo.png)