Hi ColdBox friends,
Here an the issue I am trying to solve: we have an application that
tracks proposals and are adding the ability to archive old proposals.
Once proposals are archived, they are moved into a separate database.
I am trying to figure out a way to toggle the archive on and off using
the same application code set but simply changing the datasource that
is being used. Once on, the archive state needs to persist until the
user manually toggles the archive off even if they navigate to other
pages in the application.
The gotcha is that our users may want to see both the regular system
in one browser tab and the archive system in a different browser tab
using the same browser. Because of this, I cannot track whether or not
the user is viewing the archive in either the session or client scope
or ColdBox custom settings because these variables are shared between
browser instances for an application.
I was considering using the request collection but it looks like I can
only persist variables using the Flash RAM (again, session/client/
ColdBox cache) or using the setNextEvent() method with 'persists' but
this wouldn't cover using simple links to navigate to a different page
(ie: navigation <a href links). I don't want to have to update every
link and form in the application to send a variable to the next
request collection because I'm afraid to miss any instances. Plus all
developers working on this system would have to remember to do the
same for any future development. I just don't think that is the best
The second issue: if I am able to persist a variable in the request
scope to identify whether or not the user is viewing the archive, what
is the best way to dynamically change the datasource in my model
Right now I am injecting the main datasource using (ie: inside
<cfproperty name="dsn" inject="coldbox:datasource:appDatasource" />
and then in my queries (ie: inside myModelDAO.getQueryResults()):
<cfquery name="queryName" datasource="#dsn.getName()#">
and my model method call in an event handler:
<cfset rc.queryResults = getModel("myModelDAO").getQueryResults()>
What's the best way to change the dsn that is injected to
coldbox:datasource:archiveDatasource on the fly?
Any help is greatly appreciated!