Looks right so far.
DW
Douglas Trojanwoski <mailto:[email protected]> Friday, June 21, 2013 1:55 PMOkay so i think i can get this. Well trying to wrap my head around it so only keep appSettings? and in the top of the controller only bean would be InstanceFactory<bean id="appSettings" class="model.settings.appSettings"> </bean> <entry key="productAssignment"> <map> <entry key="path"><value>model.product. assignment </value></entry> <entry key="initDependancies"> <map> <entry key="appSettings"><ref bean="appSettings" /></entry> </map> </entry> </map> </entry>On Friday, June 21, 2013 1:37:37 PM UTC-4, Dan Wilson - [email protected] wrote: ---- Model-Glue Sites: Home Page: http://www.model-glue.com Documentation: http://docs.model-glue.com Bug Tracker: http://bugs.model-glue.com Blog: http://www.model-glue.com/blog You received this message because you are subscribed to the Google Groups "model-glue" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/model-glue?hl=en ---You received this message because you are subscribed to the Google Groups "model-glue" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].For more options, visit https://groups.google.com/groups/opt_out. Dan Wilson <mailto:[email protected]> Friday, June 21, 2013 1:37 PM Yeah, there is a slight issue in your thinking.In ColdSpring, beans are generally singletons. That means a single bean exists of that type in the application scope. When you look at the product assignment bean, for example, that means you'll have 1 product assignment bean in your application scope.As you know, one or more users share the same application scope, thus when you set values by a user inside of a singleton bean, all users will see that value. This can be a good thing, but it's not going to help you get what you want out of your code.What you need to do is change how you are dealing with the product object. Since your users will need to access different product beans, depending on where they are in your application, you want to ensure your product bean is scoped to the request, not the application.I generally use createobject() for this. If I have a bean that has dependencies, like your productAssignment bean, I write a factory to get the dependencies and pass them in from ColdSpring. That way, all of your configuration can stay inside of ColdSpring, and the beans can be created per request. (or multiple times per requests, when needed).Here is an example I use:You'll see the PropertyMap is created and passed into the init() of the InstanceFactory. Depending on what is asked for, in the InstanceFactory.getBean() method, it'll look in the config for that name, and use the path along with any dependencies needed. Possibly this example is a little overkill for what you are doing, but it will give you the right idea of how to make your factory a singleton, and make your instance objects (productAssignment, etc), instance objects. All of the dependencies in the <entry key="initDependancies"> are resolved from ColdSpring, then passed into your object as an argumentcollection to the init() of your object.ColdSpring:<bean id="InstanceFactory" class="ChallengeWaveCore_CF.model.InstanceFactory"><constructor-arg name="PropertyMap"> <map> <entry key="ActivityValidator"> <map><entry key="path"><value>ChallengeWaveCore_CF.model.ActivityValidator</value></entry><entry key="initDependancies"> <map> <entry key="transfer"><ref bean="transfer" /></entry> </map> </entry> </map> </entry> <entry key="ChallengeAcceptMarker"> <map><entry key="path"><value>ChallengeWaveCore_CF.model.ChallengeAcceptMarker</value></entry><entry key="initDependancies"> <map> <entry key="transfer"><ref bean="transfer" /></entry> </map> </entry> </map> </entry> <entry key="PasswordChangeValidator"> <map><entry key="path"><value>ChallengeWaveCore_CF.model.PasswordChangeValidator</value></entry><entry key="initDependancies"> <map><entry key="CurrentMemberLoader"><ref bean="CurrentMemberLoader" /></entry></map> </entry> </map> </entry> </map> </constructor-arg> </bean> Instance Factory Code: <cfcomponent output="false"> <cfset variables.instance = structNew() /> <cffunction name="init" access="public" returntype="InstanceFactory"> <cfargument name="PropertyMap" type="struct" required="true"/> <cfset variables.instance.PropertyMap = arguments.PropertyMap /> <cfreturn this /> </cffunction><cffunction name="getBean" output="false" access="public" returntype="any" hint=""><cfargument name="BeanName" type="string" required="true"/> <cfset var loadedBean = loadFromPath( arguments.beanName ) /> <cfreturn loadedBean /> </cffunction><cffunction name="loadFromPath" output="false" access="private" returntype="any" hint=""><cfargument name="BeanName" type="string" required="true"/> <cfset var beanDef = "" /><cfif structKeyExists( variables.instance.PropertyMap, arguments.BeanName )> <cfset beanDef = createobject("component", variables.instance.PropertyMap[arguments.beanName].path ).init( argumentcollection:loadInitDependancies( arguments.beanName ) ) /><cfelse><h2>#arguments.beanName# does not exist. Please check the spelling and try again</h2><cfdump var="#variables.instance#"> <cfabort> </cfif> <cfreturn beanDef /> </cffunction><cffunction name="loadInitDependancies" output="false" access="private" returntype="any" hint=""><cfargument name="BeanName" type="string" required="true"/> <cfset var dependancyStruct = structNew() /><cfif structKeyExists( variables.instance.PropertyMap[arguments.beanName], "initDependancies")> <cfset dependancyStruct = variables.instance.PropertyMap[arguments.beanName].initDependancies /></cfif> <cfreturn dependancyStruct /> </cffunction><cffunction name="getBeanFactory" access="public" returntype="any" output="false" hint="I return the BeanFactory."><cfreturn variables.instance.beanFactory /> </cffunction><cffunction name="setBeanFactory" access="public" returntype="void" output="false" hint="I set the BeanFactory."> <cfargument name="beanFactory" type="coldspring.beans.BeanFactory" required="true" /><cfset variables.instance.beanFactory = arguments.beanFactory /> </cffunction> </cfcomponent> How to use this:<cfset local.validator = beans.instanceFactory.getBean("PasswordChangeValidator") />Douglas Trojanwoski <mailto:[email protected]> Friday, June 21, 2013 1:27 PMI have a question about how beans work and why user a looks at product A and user b looks at product B. Randomly but usually when the multi request for same page happen user b will see product a. kind of like the beans are getting overwritten.Here is how i have my setup in coldspring.xml i have productAssignment contains storedprocs to sql productHolder getters and settersappSettings contain variables based on serverlocation to set sql to look at live dev or staging servers.<bean id="productAssignment" class="model.product.assignmentt"> <constructor-arg name="appSettings"> <ref bean="appSettings" /> </constructor-arg> </bean> <bean id="productHolder" class="model.product.holder"> <constructor-arg name="appSettings"> <ref bean="appSettings" /> </constructor-arg> </bean> <bean id="appSettings" class="model.settings.appSettings"> </bean> in controller.cfc<cfcomponent output="false" hint="I am a Model-Glue controller." extends="ModelGlue.gesture.controller.Controller" beans="productAssignment,productHolder"><cffunction name="getProduct" access="public" returnType="void" output="false"><cfargument name="event" type="ModelGlue.Core.Event" required="true"> <cfset var product_id = arguments.event.getValue("product_id")><cfset var rtproducts = beans.productAssignment.getProductByID('#product_id#')><cfif rtproducts.recordcount><cfset beans.productHolder.setord_invoicestatus(rtproducts.ord_invoicestatus)><cfset beans.productHolder.setordernumber(rtproducts.ord_number)> </cfif> <cfset arguments.event.setValue("rtProducts", beans.productHolder)> </cffunction> </cfcomponent>So user goes to page to view Product i pass product_id in. it goes to beans.productAssignment.getProductByID to return a query then i set query results to beans.productHolder.If multi people hit the page and run this function sometimes if i ask for product A i get someone elses results back like for product B.Am i using beans the wrong way? Why are peoples requests getting mixed up/overwritten by someone elses.thanks -- -- Model-Glue Sites: Home Page: http://www.model-glue.com Documentation: http://docs.model-glue.com Bug Tracker: http://bugs.model-glue.com Blog: http://www.model-glue.com/blog You received this message because you are subscribed to the Google Groups "model-glue" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/model-glue?hl=en ---You received this message because you are subscribed to the Google Groups "model-glue" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].For more options, visit https://groups.google.com/groups/opt_out.
-- -- Model-Glue Sites: Home Page: http://www.model-glue.com Documentation: http://docs.model-glue.com Bug Tracker: http://bugs.model-glue.com Blog: http://www.model-glue.com/blog You received this message because you are subscribed to the Google Groups "model-glue" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/model-glue?hl=en--- You received this message because you are subscribed to the Google Groups "model-glue" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
<<inline: compose-unknown-contact.jpg>>
<<inline: postbox-contact.jpg>>
