Got it. You are right that the bean is the same.
Here is where you went astray:
<!--- menuGateway.cfc --->
<cffunction name="init">
<cfargument name="MenuBean" type="Application.Beans.MenuBean">
<cfset Variables.Bean=arguments.MenuBean>
<cfreturn THIS>
</cffunction>
This means, when the gateway is loaded, it loads an instance of the bean and
puts it in the internal variables scope. Then, when you put the bean
instance in the event scope in Model Glue, it's populated with the first set
of values. Next, you make another call to the gateway to (I assume) get
another bean with different values BUT, since your bean instance is already
in the gateway, you overwrite the bean values.
Beans (CFCs) are passed by reference.
In the Model Glue event scope, exists two references to the same bean with
the same values and this is why you get the values you do.
The more appropriate way to do this would be to create an instance of the
bean in the controller, and pass that into the service object. You should do
this each time you want another bean.
<cffunction name="loadMessageFilter" output="false" access="public"
returntype="void" hint="I set the filter">
<cfargument name="event" type="any">
<cfset var filter = arguments.event.makeEventBean(
"ChallengeWaveCore_CF.model.MessageFilter") />
<cfif arguments.event.argumentExists("ForceMediumList") IS true>
<cfset filter.setForceMediumList(
arguments.event.getArgument("ForceMediumList") ) />
</cfif>
<cfset arguments.event.setValue("MessageFilter", filter ) />
</cffunction>
<cfcomponent [...]
beans="ApplicationConfiguration,DomainService,i18nService,MenuBean,MenuGateway,MenuService,SessionService,UserService">
<cffunction name="get">
<cfargument name="event" type="any" required="true">
<cfset var AllMenuBean = arguments.event.makeEventBean("Path.To.This.Bean")
/><!-- This will make a new bean and populate any setters that match with
event values: If MenuID is in the event, and the bean has setMenuID as a
public method, it would be set for you automatically --->
<cfset var AllSameLevelMenusBean = beans.MenuService.makeNewMenuBean() />
<!-- This is another way you can make an instance bean, by putting a factory
method on your service object. This is nice because you can control how the
beans are made in one place, but not necessary --->
<cfset arguments.event.makeEventBean( AllSameLevelMenusBean ) /> <!-- Now
you can also pass a reference to a bean to the makeEventBean() method and
it'll match the Event Values and Setters for you also. Check the
docs.model-glue.com site for more detail --->
[...]
<cfset
arguments.event.setValue("languages",beans.ApplicationConfiguration.getConfigSetting("languages"))>
<cfset
arguments.event.setValue("allMenus",beans.MenuService.list(AllMenuBean))><!--
change your service to take a bean instance, rather than straight values -->
<cfset
arguments.event.setValue("allSameLevelMenus",beans.MenuService.getMenusWithSameParent(AllSameLevelMenusBean))><!--
change your service to take a bean instance, rather than straight values -->
[...]
</cffunction>
OR if you want to just pass in the straight values and not a bean, you can
do this:
<cffunction name="getMenusWithSameParent" hint="get all menus with the same
parentMenu as the specified menu">
<cfargument name="menuID" type="string" required="true"/>
<cfset var NewMenuBean = makeNewMenuBean() />
.....
Do whatever you need to populate the bean here
.....
<cfreturn NewMenuBean />
</cffunction>
You can choose which of these styles make sense for you. You just can not
put a single instance of a bean into a service object and expect references
to the bean to have different values. It will always have the last set of
values.
Make sense?
DW
On Mon, Sep 26, 2011 at 10:20 AM, marc <[email protected]> wrote:
> Ok, let me try to clarify:
>
> Let's assume the call to beans.MenuService.list() returns "1,2,3", the
> eventKey "allMenus" has a value of "123".
>
> Further, assuming the call to beans.MenuService.getMenusWithSameParent()
> returns "4,5,6", the eventKey "allSameLevelMenus" has a value of "4,5,6".
>
> So if I do this in my controller:
>
>
> <cffunction name="get">
> <cfargument name="event" type="any" required="true">
> [...] <cfset
> arguments.event.setValue("allMenus",beans.MenuService.list(local.domainId))>
> <cfset arguments.event.setValue("**allSameLevelMenus",beans.**
> MenuService.**getMenusWithSameParent(**domainId=local.domainId, parentMenu
> = local.menuBean.**getParentMenu()))>
>
> <cfdump var="#arguments.event.getValue('allMenus')#">
> <cfdump var="#arguments.event.getValue('allSameLevelMenus')#">
> [...]
>
> I expect to see this in my browser:
>
> 1,2,3
> 4,5,6
>
> (forget the extra line
>
> <cfset
> arguments.event.setValue("languages",beans.ApplicationConfiguration.getConfigSetting("languages"))>
> in my previous post)
>
> But instead I see this:
>
> 4,5,6
> 4,5,6
>
> This is menuGateway.cfc where the values are actually retrieved and
> returned:
>
> <cffunction name="init">
> <cfargument name="MenuBean" type="Application.Beans.MenuBean">
> <cfset Variables.Bean=arguments.MenuBean>
> <cfreturn THIS>
> </cffunction>
>
> <cffunction name="getMenusWithSameParent" hint="get all menus with the
> same parentMenu as the specified menu">
> [...]
> <cfreturn
> Variables.Bean.populateBeanCollection(local.Transfer.listByQuery(local.TQuery))>
> </cffunction>
>
> and
>
> <cffunction name="list" returntype="Application.Beans.MenuBean"
> hint="">
> [...]
> <cfreturn
> Variables.Bean.populateBeanCollection(local.Transfer.listByQuery(local.query))>
> </cffunction>
>
> Both methods are return the same object: first list() and then
> getMenusWithSameParent().
>
> It looks like list() populates the Variables.Bean with 1,2,3 and
> getMenusWithSameParent() populates the _same instance_ of that bean with
> 4,5,6 so in the end both eventkeys "allMenus" and "allSameLevelMenus" point
> to the same instance of Variables.Bean.
>
> I solved this by changing
>
> <cffunction name="list" returntype="Application.Beans.MenuBean"
> hint="">
> [...]
> <cfreturn
> Variables.Bean.populateBeanCollection(local.Transfer.listByQuery(local.query))>
> </cffunction>
>
> to
>
> <cffunction name="list" returntype="Application.Beans.MenuBean"
> hint="">
> [...]
> <cfreturn
> Duplicate(Variables.Bean.populateBeanCollection(local.Transfer.listByQuery(local.query)))>
> </cffunction>
>
> so Duplicate() makes sure _another_ instance of Variables.Bean is returned
> instead of the same instance.
>
> But this is clumsy - I cannot use Duplicate() on an ad-hoc basis.
>
> I hope I made my question clear. If not, just ask ask again.
>
> Marc
>
> --
> 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
>
--
Plutarch - "The mind is not a vessel to be filled but a fire to be kindled."
--
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