OOP Coldfusion
Hi All, I'm working on an OOP project and am having a bit of a problem with objects referencing each other. My folder structure is /siteRoot/ /siteRoot/core (Where all my classes are) /siteRoot/core/valueObjects I'm quite early on in the build so I'm just setting up my value classes. I've got two classes in there, one called Page, the other called Head. Back at the root I'm instantiating these classes in a cfm file called testing. cfset page = CreateObject(component,core.valueObjects.Page).init() cfset head = CreateObject(component,core.valueObjects.Head).init(title:This is a new title) So far so cool. The problem is that one of the properties of the Page class is a Head object. This is populated with this function in the Page class cffunction name=setHead access=public hint=Sets the Head Object cfargument name=head type=core.valueObjects.Head required=yes cfset variables.head = ARGUMENTS.head /cffunction However when I call the function from the testing page with : cfset page.setHead(head) I get an error : - The HEAD argument passed to the setHead function is not of type core.valueObjects.Head. When as far as I'm concerned it is. The fix I came up with is to change the argument in the setHead function to be only Head. Now this sort of works as Page and Had live in the same folder, but I can see problems further down the line unless I get this clear in my head. So am I a - doing this wrong, should there be a special place or method of creating CF classes where they can reference each other with complete class paths? b - Just accept that the classes can only reference each other relatively? c - Go back to actionscript and stop pretending to be a server side coder? Thanks in advance Tim ~| Get the answers you are looking for on the ColdFusion Labs Forum direct from active programmers and developers. http://www.adobe.com/cfusion/webforums/forum/categories.cfm?forumid-72catid=648 Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:290850 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: OOP Coldfusion
The quick way to fix this issue is to just set the argument type to any. Coldfusion is dynamic and can handle that just fine. However, this can make debugging the app more difficult because instead of getting a helpful type-casting error, you may get something like tthe method cannot be found, further down the line of code execution. The slower way to fix this issue, and probably the better in the long run way, would be to learn and use ColdSpring to handle your object instantiation and dependencies. Using ColdSpring, you would declare the classes and their dependencies in an xml file and then do something like cfset page = application.CSFactory.getBean('page') / It will already have an instance of head in it because of the xml declarations. Matt On 10/11/07, Tim Ashworth [EMAIL PROTECTED] wrote: Hi All, I'm working on an OOP project and am having a bit of a problem with objects referencing each other. My folder structure is /siteRoot/ /siteRoot/core (Where all my classes are) /siteRoot/core/valueObjects I'm quite early on in the build so I'm just setting up my value classes. I've got two classes in there, one called Page, the other called Head. Back at the root I'm instantiating these classes in a cfm file called testing. cfset page = CreateObject(component,core.valueObjects.Page).init() cfset head = CreateObject(component,core.valueObjects.Head).init(title:This is a new title) So far so cool. The problem is that one of the properties of the Page class is a Head object. This is populated with this function in the Page class cffunction name=setHead access=public hint=Sets the Head Object cfargument name=head type=core.valueObjects.Head required=yes cfset variables.head = ARGUMENTS.head /cffunction However when I call the function from the testing page with : cfset page.setHead(head) I get an error : - The HEAD argument passed to the setHead function is not of type core.valueObjects.Head. When as far as I'm concerned it is. The fix I came up with is to change the argument in the setHead function to be only Head. Now this sort of works as Page and Had live in the same folder, but I can see problems further down the line unless I get this clear in my head. So am I a - doing this wrong, should there be a special place or method of creating CF classes where they can reference each other with complete class paths? b - Just accept that the classes can only reference each other relatively? c - Go back to actionscript and stop pretending to be a server side coder? Thanks in advance Tim ~| ColdFusion 8 - Build next generation apps today, with easy PDF and Ajax features - download now http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:290859 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: OOP Coldfusion
Tim, I am not 100% sure, but I have come across this before and I think it has to do with loading the cfc from the current directory. Others like Sean might give a better explanation, but my fix has been to create a mapping for core or to use /core.package.component. On 10/11/07, Tim Ashworth [EMAIL PROTECTED] wrote: Hi All, I'm working on an OOP project and am having a bit of a problem with objects referencing each other. My folder structure is /siteRoot/ /siteRoot/core (Where all my classes are) /siteRoot/core/valueObjects I'm quite early on in the build so I'm just setting up my value classes. I've got two classes in there, one called Page, the other called Head. Back at the root I'm instantiating these classes in a cfm file called testing. cfset page = CreateObject(component,core.valueObjects.Page).init() cfset head = CreateObject(component,core.valueObjects.Head).init(title:This is a new title) So far so cool. The problem is that one of the properties of the Page class is a Head object. This is populated with this function in the Page class cffunction name=setHead access=public hint=Sets the Head Object cfargument name=head type=core.valueObjects.Head required=yes cfset variables.head = ARGUMENTS.head /cffunction However when I call the function from the testing page with : cfset page.setHead(head) I get an error : - The HEAD argument passed to the setHead function is not of type core.valueObjects.Head. When as far as I'm concerned it is. The fix I came up with is to change the argument in the setHead function to be only Head. Now this sort of works as Page and Had live in the same folder, but I can see problems further down the line unless I get this clear in my head. So am I a - doing this wrong, should there be a special place or method of creating CF classes where they can reference each other with complete class paths? b - Just accept that the classes can only reference each other relatively? c - Go back to actionscript and stop pretending to be a server side coder? Thanks in advance Tim ~| Check out the new features and enhancements in the latest product release - download the What's New PDF now http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:290863 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: OOP Coldfusion
Thanks for the reply Matt, I have to confess I'm not particularly looking forward to learning a framework. I was sort of hoping that defining class paths to cfcs would be a setting somewhere.. I ColdSpring sounds cool tho, I'll check it out. Thanks again Tim -Original Message- From: Matt Williams [mailto:[EMAIL PROTECTED] Sent: 11 October 2007 15:17 To: CF-Talk Subject: Re: OOP Coldfusion The quick way to fix this issue is to just set the argument type to any. Coldfusion is dynamic and can handle that just fine. However, this can make debugging the app more difficult because instead of getting a helpful type-casting error, you may get something like tthe method cannot be found, further down the line of code execution. The slower way to fix this issue, and probably the better in the long run way, would be to learn and use ColdSpring to handle your object instantiation and dependencies. Using ColdSpring, you would declare the classes and their dependencies in an xml file and then do something like cfset page = application.CSFactory.getBean('page') / It will already have an instance of head in it because of the xml declarations. Matt On 10/11/07, Tim Ashworth [EMAIL PROTECTED] wrote: Hi All, I'm working on an OOP project and am having a bit of a problem with objects referencing each other. My folder structure is /siteRoot/ /siteRoot/core (Where all my classes are) /siteRoot/core/valueObjects I'm quite early on in the build so I'm just setting up my value classes. I've got two classes in there, one called Page, the other called Head. Back at the root I'm instantiating these classes in a cfm file called testing. cfset page = CreateObject(component,core.valueObjects.Page).init() cfset head = CreateObject(component,core.valueObjects.Head).init(title:This is a new title) So far so cool. The problem is that one of the properties of the Page class is a Head object. This is populated with this function in the Page class cffunction name=setHead access=public hint=Sets the Head Object cfargument name=head type=core.valueObjects.Head required=yes cfset variables.head = ARGUMENTS.head /cffunction However when I call the function from the testing page with : cfset page.setHead(head) I get an error : - The HEAD argument passed to the setHead function is not of type core.valueObjects.Head. When as far as I'm concerned it is. The fix I came up with is to change the argument in the setHead function to be only Head. Now this sort of works as Page and Had live in the same folder, but I can see problems further down the line unless I get this clear in my head. So am I a - doing this wrong, should there be a special place or method of creating CF classes where they can reference each other with complete class paths? b - Just accept that the classes can only reference each other relatively? c - Go back to actionscript and stop pretending to be a server side coder? Thanks in advance Tim ~| ColdFusion 8 - Build next generation apps today, with easy PDF and Ajax features - download now http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:290864 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: OOP Coldfusion
Also, as Matt said, this sort of thing screams ColdSpring: cfset page = CreateObject(component,core.valueObjects.Page).init() cfset head = CreateObject(component,core.valueObjects.Head).init(title:This is a new title) cfset page.setHead(head) Trust me, if you're serious about building OO CFC-based apps, this only going to get worse and worse. Save yourself a lot of pain and just learn ColdSpring right now. ;-) On 10/11/07, Brian Kotek [EMAIL PROTECTED] wrote: You can try clearing the template cache in the CF administrator. Sometimes the way CF stores CFCs in its cache can screw things up when it comes to typing if you have moved things around, changed names, or instantiated the same component from multiple folders. It thinks the type is pointing somewhere else. On 10/11/07, Tim Ashworth [EMAIL PROTECTED] wrote: Thanks for the reply Matt, I have to confess I'm not particularly looking forward to learning a framework. I was sort of hoping that defining class paths to cfcs would be a setting somewhere.. I ColdSpring sounds cool tho, I'll check it out. Thanks again Tim ~| Enterprise web applications, build robust, secure scalable apps today - Try it now ColdFusion Today ColdFusion 8 beta - Build next generation apps Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:290868 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: OOP Coldfusion
You can try clearing the template cache in the CF administrator. Sometimes the way CF stores CFCs in its cache can screw things up when it comes to typing if you have moved things around, changed names, or instantiated the same component from multiple folders. It thinks the type is pointing somewhere else. On 10/11/07, Tim Ashworth [EMAIL PROTECTED] wrote: Thanks for the reply Matt, I have to confess I'm not particularly looking forward to learning a framework. I was sort of hoping that defining class paths to cfcs would be a setting somewhere.. I ColdSpring sounds cool tho, I'll check it out. Thanks again Tim ~| Check out the new features and enhancements in the latest product release - download the What's New PDF now http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:290867 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: OOP Coldfusion
Tim Did you try and set up a mapping to the top level of your components directory? Frame works are a good thing, they take a lot of these types of questions away from you so you can concentrate on what it is you need to concentrate on, that being the solution to the problem. Whether its Mach-2, FuseBox, Model-Glue, ColdSpring or IrishSpring (just joking on this one) they all have their pros and cons. Asking which one is better will end up in a fire storm debate :) Try ColdSpring if you like how it works use it, otherwise try another and so on. Yes it takes time but you are the best person to judge which one best fits with how you think. Regards, -- Gary Gilbert http://www.garyrgilbert.com/blog ~| Get the answers you are looking for on the ColdFusion Labs Forum direct from active programmers and developers. http://www.adobe.com/cfusion/webforums/forum/categories.cfm?forumid-72catid=648 Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:290869 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: OOP Coldfusion
Just to be clear though, ColdSpring is a dependency injection framework for your model and has nothing to do with the front controller frameworks like Mach-II or Fusebox. They do totally different things (ColdSpring works with any of the front-controller frameworks, or with no framework at all). On 10/11/07, gary gilbert [EMAIL PROTECTED] wrote: Whether its Mach-2, FuseBox, Model-Glue, ColdSpring or IrishSpring (just joking on this one) they all have their pros and cons. Asking which one is better will end up in a fire storm debate :) Try ColdSpring if you like how it works use it, otherwise try another and so on. ~| ColdFusion 8 - Build next generation apps today, with easy PDF and Ajax features - download now http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:290870 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: OOP Coldfusion
Hi Gary et al, Thanks for everyone's help. I managed to solve the problem, I assumed my mapping was working when it wasn't :( After changing the mapping all sorted. I'm going to look into Coldspring and the other frameworks in more detail, but as I'm still nowhere near being a CF nerd yet, and as the app I'm creating isn't too involved, I'm going to continue as I am as a learning exercise in CF. Once I've got my head a bit more round that then I should be able to relate what I've learnt across to the frameworks. It's sort of the way my brain works.. Having said that tho - which is the best framework? *ducks* Only joking ;) -Original Message- From: gary gilbert [mailto:[EMAIL PROTECTED] Sent: 11 October 2007 16:15 To: CF-Talk Subject: Re: OOP Coldfusion Tim Did you try and set up a mapping to the top level of your components directory? Frame works are a good thing, they take a lot of these types of questions away from you so you can concentrate on what it is you need to concentrate on, that being the solution to the problem. Whether its Mach-2, FuseBox, Model-Glue, ColdSpring or IrishSpring (just joking on this one) they all have their pros and cons. Asking which one is better will end up in a fire storm debate :) Try ColdSpring if you like how it works use it, otherwise try another and so on. Yes it takes time but you are the best person to judge which one best fits with how you think. Regards, -- Gary Gilbert http://www.garyrgilbert.com/blog ~| Create robust enterprise, web RIAs. Upgrade to ColdFusion 8 and integrate with Adobe Flex http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJP Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:290872 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: OOP Coldfusion
On 10/11/07, Matt Williams [EMAIL PROTECTED] wrote: On 10/11/07, Tim Ashworth [EMAIL PROTECTED] wrote: Having said that tho - which is the best framework? ColdMachTransfer-ReactorFuseGlue But be sure to get the BER from SVN or CVS or Walgreens, or something. :P -- Matt Williams It's the question that drives us. ~| Create robust enterprise, web RIAs. Upgrade to ColdFusion 8 and integrate with Adobe Flex http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJP Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:290879 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: OOP Coldfusion
On 10/11/07, Tim Ashworth [EMAIL PROTECTED] wrote: Having said that tho - which is the best framework? ColdMachTransfer-ReactorFuseGlue -- Matt Williams It's the question that drives us. ~| ColdFusion 8 - Build next generation apps today, with easy PDF and Ajax features - download now http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:290878 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4