Hi,
I actually have 2 questions: about the possibility of Bean data getting
corrupted by multilpe requests and the use of Transfer objects in my views.
I have a ModelGlue application where I use ModelGlue,Coldspring (1.2) and
Transfer. Currently, a request for a page looks like this:
MG gets request "Page.get"
1) function get() in Controller Page.cfc gets called
2) function get() in Service Page.cfc gets called
3) function get() in Gateway Page.cfc gets called.
4) function get() in Gateway Page.cfc uses Transfer to get data from db and
returns a Transfer object.
then the chain reverses:
5) Gateway returns result to Service
6) Service returns result to Controller
7) Controller places Bean in eventscope.
8) The View reads and displays values from the Transfer bean.
What I want to do in step 6 before returning values to the Controller is to
copy the values in te Transfer Bean returned from the Gateway to a Bean I
created (call it "MyBean"). I want this for several reasons:
1) my View does not have to have knowledge of Transfer to retrieve values
from the Bean but can just call getters to retrieve values.
2) I can manipulate the values returned by Transfer before populating the
bean so instead of calling a getContent() on the bean which returns me a 255
long string I can add a getShortContent() theat returns a max 55 character
string;
3) I can for example create a struct consisting of values located in
multiple related objects whereby I otherwise would have to put the Transfer
logic to retrieve these values in the view. For Example: ask a menu object
to "get me a menutitle based on language" where menuobject has a 12m
relation to menutitle object which has a m21 relation to language object. I
don't know how to do this without manually iterating through arrays of
Transfer objects and comparing values
Currently I do this by copying the values from the transfer object to a new
bean and have that bean used by the View to display data. The new bean
contains the functions that provide the data I need in the form I need.
Question 1:
Is this use of a custom Bean a good approach or am I better off using
decorators for the Transfer objects?
My Service component looks like this (abbreviated):
<cfcomponent accessors="true" name="myService">
<cfproperty name="DataBean">
<cfproperty name="DataGateWay">
<cffunction name="get">
<cfargument name="id">
<cfset myBean=getDataBean()>
<cfset myTransferObject=getDataGateWay(arguments.id)>
<cfreturn getDataBean().populate(myTransferObject)>
</cffunction>
I understand the dependency injection works like this: at ApplicationStart()
Coldspring injects an instance of a new DataBean in the Service. Because I
have the MG option "reloadBeanFactory" set to true in development mode,
every time I call function get() on the Page controller, the service returns
a new instance of the DataBean. But in production "reloadBeanFactory" will
be set to false so every request to PageController returns the same instance
of this populated Bean.
That will work fine when a requests ends displaying the contents of the Bean
before another request will populate the Bean. But what if request A is in
the process of displaying values from the Bean and then another request B
calls getDataBean().populate(myTransferObject)? Will the Bean suddenly start
returning values that are modified by the interrupting request B?
Question 2
Is this a credible scenario and if so, what are my options here?
I hope this post is not too confusing. If so, just ask, I'll try to clarify.
Thanks,
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