|
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Why is ColdFusion giving me grief over this code?
?Rick Faircloth 05/29/08 11:59 A you have to close the CFSWITCH tagBarney Boisvert 05/29/08 12:02 P You need to have a closing cfswitch containing cfcases for it to work.Loathe 05/29/08 12:02 P On Thu, May 29, 2008 at 8:57 AM, Rick FairclothCharlie Griefer 05/29/08 12:04 P On Thu, May 29, 2008 at 9:02 AM, Charlie GrieferCharlie Griefer 05/29/08 12:10 P Thanks, everyone, for clearing that up.Rick Faircloth 05/29/08 12:15 P On Thu, May 29, 2008 at 9:13 AM, Rick FairclothCharlie Griefer 05/29/08 12:38 P Yes...Andy Matthews 05/29/08 12:51 P > i think there's a custom tag out there that will automagically putDominic Watson 05/29/08 02:05 P On Thu, May 29, 2008 at 11:03 AM, Dominic WatsonCharlie Griefer 05/29/08 02:16 P Oh yeh, missed that one ;)Dominic Watson 05/29/08 02:52 P Steve Nelson had a tag formurl2attributes.cfmLoathe 05/29/08 12:15 P I have a function that does that. It is pretty old so don't make fun ofGerald Guido 05/29/08 12:26 P Oh yeah....Gerald Guido 05/29/08 12:28 P I did not look at the function but out of curiosity why not just use theAaron Rouse 05/29/08 12:35 P Slaps head....Gerald Guido 05/29/08 12:37 P Rick Faircloth wrote:Ian Skinner 05/29/08 12:06 P On a side note... is it better to useBrad Wood 05/29/08 12:37 P ? <cfif isdefined('url.property_type')> <cfswitch expression='#url.property_type#'> <cfelse> <cfswitch expression='#form.property_type#'> </cfif> It's complaining with this error: Context validation error for the cfelse tag. The tag must be nested inside a CFIF tag. Can cfswitch tags not be nested inside cfif tags? Rick you have to close the CFSWITCH tag On Thu, May 29, 2008 at 8:57 AM, Rick Faircloth <Rick@whitestonemedia.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- You need to have a closing cfswitch containing cfcases for it to work. Rick Faircloth wrote: ----- Excess quoted text cut - see Original Post for more ----- On Thu, May 29, 2008 at 8:57 AM, Rick Faircloth <Rick@whitestonemedia.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- not like that, no. you need to finish the switch inside of each condition. would be "better" to do: <cfif structKeyExists(url, 'property_type')> <cfset variables.property_type = URL.property_type /> </cfif> <cfif structKeyExists(form, 'property_type')> <cfset variables.property_type = form.property_type /> </cfif> then <cfswitch expression="#variables.property_type#"> (case statements) </cfswitch> i think there's a custom tag out there that will automagically put form/URL vars into an "attributes" scope. This is how fusebox does it by default (and in Model-Glue it's in the 'event')... but I seem to recall a custom tag that would accomplish the same end for folks who aren't using a framework. -- A byte walks into a bar and orders a pint. Bartender asks him "What's wrong?" Byte says "Parity error." Bartender nods and says "Yeah, I thought you looked a bit off." On Thu, May 29, 2008 at 9:02 AM, Charlie Griefer <charlie.griefer@gmail.com> wrote: > i think there's a custom tag out there that will automagically put > form/URL vars into an "attributes" scope. This is how fusebox does it > by default (and in Model-Glue it's in the 'event')... but I seem to > recall a custom tag that would accomplish the same end for folks who > aren't using a framework. as a followup... here's that custom tag. http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&extid=1001246 -- A byte walks into a bar and orders a pint. Bartender asks him "What's wrong?" Byte says "Parity error." Bartender nods and says "Yeah, I thought you looked a bit off." Thanks, everyone, for clearing that up. On a side note... is it better to use 'structKeyExists(url, 'property_type')' as opposed to 'isdefined('url.property_type')' ??? And, if so, why? Thanks, Rick ----- Excess quoted text cut - see Original Post for more ----- On Thu, May 29, 2008 at 9:13 AM, Rick Faircloth <Rick@whitestonemedia.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- http://corfield.org/blog/index.cfm/do/blog.entry/entry/isDefined_vs_structKeyExists -- A byte walks into a bar and orders a pint. Bartender asks him "What's wrong?" Byte says "Parity error." Bartender nods and says "Yeah, I thought you looked a bit off." Yes... StructKeyExists is better in most cases. Thanks, everyone, for clearing that up. On a side note... is it better to use 'structKeyExists(url, 'property_type')' as opposed to 'isdefined('url.property_type')' ??? And, if so, why? Thanks, Rick ----- Excess quoted text cut - see Original Post for more ----- condition. ----- Excess quoted text cut - see Original Post for more ----- > i think there's a custom tag out there that will automagically put form/URL vars into an "attributes" scope. Can be done natively in CF with two lines of code: request.args = url; StructAppend(request.args, form); Et voila Dominic -- Blog it up: http://fusion.dominicwatson.co.uk On Thu, May 29, 2008 at 11:03 AM, Dominic Watson <watson.dominic@googlemail.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- ya, aaron mentioned that earlier in the thread. very nice. i never even thought about that route :\ -- A byte walks into a bar and orders a pint. Bartender asks him "What's wrong?" Byte says "Parity error." Bartender nods and says "Yeah, I thought you looked a bit off." Oh yeh, missed that one ;) 2008/5/29 Charlie Griefer <charlie.griefer@gmail.com>: ----- Excess quoted text cut - see Original Post for more ----- Steve Nelson had a tag formurl2attributes.cfm I can't seem to find it for download though. Charlie Griefer wrote: ----- Excess quoted text cut - see Original Post for more ----- I have a function that does that. It is pretty old so don't make fun of me..... but it works ;) http://pastebin.com/m6d287cb5 On Thu, May 29, 2008 at 12:14 PM, Loathe <timothy.heald@gmail.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- Oh yeah.... Usage: PopulateStruct(form,url) On Thu, May 29, 2008 at 12:24 PM, Gerald Guido <gerald.guido@gmail.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- I did not look at the function but out of curiosity why not just use the StructAppend() built into CF? I often copy the URL scope into the Form on some of our pages due to not know if a value will be passed in by one or the other. So I just put in a <cfset StructAppend(FORM, URL, false) /> for those needs. On Thu, May 29, 2008 at 11:24 AM, Gerald Guido <gerald.guido@gmail.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- Slaps head.... On Thu, May 29, 2008 at 12:33 PM, Aar ----- Excess quoted text cut - see Original Post for more ----- Rick Faircloth wrote: > Can cfswitch tags not be nested inside cfif tags? > > Rick The whole <cfswitch...> tag can be, but not just the first half. I.E. <cfif... <cfswittch>...</cfswitch> <cfelse> <cfswitch>...</cfswitch> </crif> Allowed. <cfif... <cfswittch> <cfelse> <cfswitch> </crif> </cfswitch> Not Allowed. The quikest fix to what you are trying to do would be. <cfswitch expression(#iif(isDefined('url.property_type',de(url.property_type),de(form.property_type))#) But this is they type of solution the usually quickly gets re-factored into cleaner and simpler code. On a side note... is it better to use 'structKeyExists(url, 'property_type')' as opposed to 'isdefined('url.property_type')' =========================================== The answer is a resounding "depends". It depends on: 1) Version of Coldfusion 2) Whether or not the variable exists. 3) How many variables are in the url scope. My main beef with isdefined is that it scope hunts and if the variable is not defined it may take longer to return false. Structkeyexists is a bit more verbose about what you are looking for. The fact of the matter is you are talking a difference of milliseconds. I have measured a difference before, but I had to loop thousands of times for it to add up and that isn't a very reliable test to compare a production app against. Here's the general consensus on this kind of stuff: Code what is the easiest to read and maintain. If you have a performance problem with the code, address it at that time. ~Brad
|
Mailing Lists
|
Latest Fusion Authority Articles
|
||||||