How to access settings defined in coldbox.xml.cfm from within model objects?

Hi,

In one of my model objects, I tried to inject a setting I defined in
the <YourSettings> section of coldbox.xml.cfm by following what I read
in the ColdBox Model Guide. But when I tried to access the setting in
one of the object's functions, I get error saying that the Element
SITEDOMAIN is undefined in VARIABLES.

This is how I injected the SITEDOMAIN setting.

<cfcomponent output="false" autowire="true" ...>
    <cfproperty name="siteDomain" type="coldbox:setting:siteDomain"
scope="variables">
    .
    .
    .
    <cffunction ...>
        <cfreturn
"#variables.instance.subdomain#.#variables.siteDomain">
    </cffunction>
    .
    .
    .
</cfcomponent>

I tried using "instance" scope for the cfproperty and same result.
I'm currently using CF9.0.1 and ColdBox 2.6.4.

Thanks,
JY

Oh, for the <cfreturn ...> line in my initial post, I forgot to type
the closing #. The actual code is fine.

Check out the autowiring docs guide.

With autowiring you can inject a setting something like this:

// inject into variables scope
cfproperty name"mySetting" type="coldbox:setting:mySetting";

Aaron Greenlee

http://aarongreenlee.com/
Twitter: aarongreenlee

Yeah, that's what I did if you looked at the sample code I included in
my initial post. =)

I am on a computer now and see that you are using 2.6.4.

The syntax appears correct. Did you reinit after adding the property?

Also, do you have the autowire interceptor enabled in your config.

<Interceptor class="coldbox.system.interceptors.autowire">
  <Property name="debugMode">true</Property>
  <Property name="completeDIMethodName">onDIComplete</Property>
  <Property name="enableSetterInjection">true</Property>
</Interceptor>

And how are you calling your model? Using getModel()?

Hope that helps.

Curt Gratz
Computer Know How

Does <cfreturn siteDomain /> not work for you?

Also what version of COldBox are you running, from 3.0M5/M6 the autowire is
no longer required.

Regards,
Andrew Scott
http://www.andyscott.id.au/

Yep, I reinited CB after adding the cfproperty and enabling the
autowire interceptor.

Does "enableSetterInjection" need to be set to true when using
cfproperty approach? I left it as "false", which was the default
value in the coldbox.xml.cfm file.

Oh, I'm not calling getModel(). I'm using Coldspring and I have a
SiteService (model) component that I inject to the handler. The
SiteService has methods that can return a Site component.

Nope, <cfreturn siteDomain /> doesn't work.

Running CB 2.6.4.

Please post your coldbox configuration file and your model.

Thx.

Aaron Greenlee

http://aarongreenlee.com/
Twitter: aarongreenlee

coldbox configuration file:

<?xml version="1.0" encoding="UTF-8"?>
<Config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="http://www.coldboxframework.com/schema/
config_2.6.0.xsd">
  <Settings>
    <!--The name of your application.-->
    <Setting name="AppName" value="ws3"/>
    <!-- ColdBox set-up information for J2EE installation.
      As context-root are actually virtual locations which does not
correspond to physical location of files. for example
      /openbd /var/www/html/tomcat/deploy/bluedragon

      AppMapping setting will adjust physical location of Project/App
files and coldbox will load handlers,plugis,config file etc
      Create a cf mapping and enable this value.
      /MyApp /var/www/html/tomcat/deploy/bluedragon/MyAppFolder

      If you are using a coldbox app to power flex/remote apps, you NEED
to set the AppMapping also. In Summary,
      the AppMapping is either a CF mapping or the path from the webroot
to this application root. If this setting
      is not set, then coldbox will try to auto-calculate it for you.
Please read the docs.

      <Setting name="AppMapping" value="/MyApp"/>

    -->
    <!--Default Debugmode boolean flag (Set to false in production
environments)-->
    <Setting name="DebugMode" value="false" />
    <!--The Debug Password to use in order to activate/deactivate
debugmode,activated by url actions -->
    <Setting name="DebugPassword" value=""/>
    <!--The fwreinit password to use in order to reinitialize the
framework and application.Optional, else leave blank -->
    <Setting name="ReinitPassword" value=""/>
    <!--Event Name -->
    <Setting name="EventName" value="event"/>
    <!--This feature is enabled by default to permit the url dumpvar
parameter-->
    <Setting name="EnableDumpVar" value="true" />
    <!--Log Errors and entries on the coldfusion server logs, disabled
by default if not used-->
    <Setting name="EnableColdfusionLogging" value="false" />
    <!--Log Errors and entries in ColdBox's own logging facilities. You
choose the location, finally per application logging.-->
    <Setting name="EnableColdboxLogging" value="true" />
    <!--The absolute or relative path to where you want to store your
log files for this application-->
    <Setting name="ColdboxLogsLocation" value="logs" />
    <!--
      The default logging level to use. Defaults to all = 4 valid numbers
are 0-4
      0-fatal,1-error,2-warning,3-information,4-debug
      <Setting name="DefaultLogLevel" value="4" />
    -->
    <!--Default Event to run if no event is set or passed. Usually the
event to be fired first (NOTE: use event handler syntax)-->
    <Setting name="DefaultEvent" value="general.index"/>
    <!--Event Handler to run on the start of a request, leave blank if
not used. Emulates the Application.cfc onRequestStart method -->
    <Setting name="RequestStartHandler" value="main.onRequestStart"/>
    <!--Event Handler to run at end of all requests, leave blank if not
used. Emulates the Application.cfc onRequestEnd method-->
    <Setting name="RequestEndHandler" value=""/>
    <!--Event Handler to run at the start of an application, leave blank
if not used. Emulates the Application.cfc onApplicationStart method --

    <Setting name="ApplicationStartHandler" value="main.onAppInit"/>
    <!--Event Handler to run at the start of a session, leave blank if
not used.-->
    <Setting name="SessionStartHandler" value=""/>
    <!--Event Handler to run at the end of a session, leave blank if not
used.-->
    <Setting name="SessionEndHandler" value=""/>
    <!--The Email address from which all outgoing framework emails will
be sent. -->
    <Setting name="OwnerEmail" value="" />
    <!-- Enable Bug Reports to be emailed out, set to true by default if
left blank -->
    <Setting name="EnableBugReports" value="false"/>
    <!--UDF Library To Load on every request for your views and handlers
-->
    <Setting name="UDFLibraryFile" value="/includes/helpers/
ApplicationHelper.cfm" />
    <!--The event handler to execute on all framework exceptions. Event
Handler syntax required.-->
    <Setting name="ExceptionHandler" value="" />
    <!--What event to fire when an invalid event is detected-->
    <Setting name="onInvalidEvent" value="general.index" />
    <!--Full path from the application's root to your custom error page,
else leave blank. -->
    <Setting name="CustomErrorTemplate" value="" />
    <!--Messagebox Style (css) class name to use. Look at the
messagebox.cfm in the includes directory-->
    <Setting name="MessageboxStyleOverride" value="false" />
    <!--Flag to Auto reload the internal handlers directory listing.
False for production. -->
    <Setting name="HandlersIndexAutoReload" value="false" />
    <!--Flag to auto reload the config.xml settings. False for
production. -->
    <Setting name="ConfigAutoReload" value="false" />
    <!-- Declare the custom plugins base invocation path, if used. You
have to use dot notation.Example: mymapping.myplugins -->
    <Setting name="MyPluginsLocation" value="" />
    <!-- Declare the external views location. It can be relative to this
app or external. This in turn is used to do cfincludes. -->
    <Setting name="ViewsExternalLocation" value=""/>
    <!-- Declare the external handlers base invocation path, if used.
You have to use dot notation.Example: mymapping.myhandlers -->
    <Setting name="HandlersExternalLocation" value="" />
    <!-- Declare the external models base invocation path, if used. You
have to use dot notation.Example: mymapping.mymodels -->
    <Setting name="ModelsExternalLocation" value="" />
    <!-- Caching of model objects via model integration -->
    <Setting name="ModelsObjectCaching" value="true" />

    <!-- Uncomment More Model Integration Settings:
      <Setting name="ModelsSetterInjection" value="false" />
      <Setting name="ModelsDICompleteUDF" value="onDIComplete" />
      <Setting name="ModelsStopRecursion" value="" />
      <Setting name="ModelsDebugMode" value="true" />
    -->
    <!--Flag to cache handlers. Default if left blank is true. -->
    <Setting name="HandlerCaching" value="false"/>
    <!--Flag to cache events if metadata declared. Default is true -->
    <Setting name="EventCaching" value="false"/>
    <!--IOC Framework if Used, else leave blank-->
    <Setting name="IOCFramework" value="coldspring" />
    <!-- Reload IOC Framework on every request, usually for development
or debugging -->
    <Setting name="IOCFrameworkReload" value="false" />
    <!--IOC Definition File Path, relative or absolute -->
    <Setting name="IOCDefinitionFile" value="/com/coldspring.xml" />
    <!--IOC Object Caching, true/false. For ColdBox to cache your IoC
beans-->
    <Setting name="IOCObjectCaching" value="false" />
    <!--Request Context Decorator, leave blank if not using. Full
instantiation path -->
    <Setting name="RequestContextDecorator" value=""/>
    <!--Flag if the proxy returns the entire request collection or what
the event handlers return, default is false -->
    <Setting name="ProxyReturnCollection" value="false"/>
    <!-- What scope are flash persistance variables using. -->
    <Setting name="FlashURLPersistScope" value="session"/>
  </Settings>

  <!-- Your Settings can go here, if not needed, use <YourSettings />.
You can use these for anything you like.
    <YourSettings>
    <Setting name="MySetting" value="My Value"/>

    whether to encrypt the values or not
    <Setting name="cookiestorage_encryption" value="true"/>

    The encryption seed to use. Else, use a default one (Not Recommened)
    <Setting name="cookiestorage_encryption_seed" value="mykey"/>

    The encryption algorithm to use (According to CFML Engine)
    <Setting name="cookiestorage_encryption_algorithm"
value="CFMX_COMPAT or BD_DEFAULT"/>

    Messagebox Plugin (You can now override the storage scope without
affecting all framework applications)
    <Setting name="messagebox_storage_scope" value="session or client" /

    Complex Settings follow JSON Syntax. www.json.org.
    *IMPORTANT: use single quotes in this xml file for JSON notation,
ColdBox will translate it to double quotes.
    </YourSettings>
  -->
   <YourSettings>
    <Setting name="wwwDsn" value="ws3_www"/>
    <Setting name="engineDsn" value="ws3_engine"/>
    <Setting name="uploadFolder" value="E:\Web\upload"/>
    <!-- site domain -->
    <Setting name="siteDomain" value="website.dev"/>

    <Setting name="jqueryPath" value="http://ajax.googleapis.com/ajax/
libs/jquery/1.4.2/jquery.min.js"/>
    <Setting name="jqueryUIPath" value="http://ajax.googleapis.com/ajax/
libs/jqueryui/1.8.4/jquery-ui.min.js"/>
    <Setting name="jqueryUIThemePath" value="http://ajax.googleapis.com/
ajax/libs/jqueryui/1.8.4/themes/redmond/jquery-ui.css"/>

    <Setting name="EmailPath" value="E:\Web\ws3\com\email\templates" />
  </YourSettings>

  <!-- Custom Conventions : You can override the framework wide
conventions
  -->
    <Conventions>
      <handlersLocation>handlers</handlersLocation>
      <pluginsLocation>plugins</pluginsLocation>
      <layoutsLocation>layouts</layoutsLocation>
      <viewsLocation>views</viewsLocation>
      <eventAction>index</eventAction>
      <modelsLocation>com</modelsLocation>
    </Conventions>

  <!--
    Control the ColdBox Debugger. The panels are self explanatory. The
other settings are explained below.
    PersistentRequestProfiler : Activate the event profiler across
multiple requests
    maxPersistentRequestProfilers : Max records to keep in the profiler.
Don't get gready.
    maxRCPanelQueryRows : If a query is dumped in the RC panel, it will
be truncated to this many rows.
  -->
    <DebuggerSettings>
      <PersistentRequestProfiler>true</PersistentRequestProfiler>
      <maxPersistentRequestProfilers>10</maxPersistentRequestProfilers>
      <maxRCPanelQueryRows>50</maxRCPanelQueryRows>

      <TracerPanel show="true" expanded="true" />
      <InfoPanel show="true" expanded="true" />
      <CachePanel show="true" expanded="false" />
      <RCPanel show="true" expanded="false" />
    </DebuggerSettings>

  <!--Optional,if blank it will use the CFMX administrator settings.-->
  <MailServerSettings>
    <MailServer></MailServer>
    <MailPort></MailPort>
    <MailUsername></MailUsername>
    <MailPassword></MailPassword>
  </MailServerSettings>

  <!--Emails to Send bug reports, you can create as many as you like-->
  <BugTracerReports/>

  <!--Webservice declarations your use in your application, if not use,
leave blank
  Note that for the same webservice name you can have a development url
and a production url.
  <WebService name="TESTWS" URL="http://www.test.com/test.cfc?wsdl"
DevURL="http://dev.test.com/test.cfc?wsdl" />
  -->
  <WebServices />
  <!--Declare Layouts for your application here-->
  <Layouts>
    <!--Declare the default layout, MANDATORY-->
    <DefaultLayout>main.cfm</DefaultLayout>

    <!--Declare other layouts, with view assignments if needed, else do
not write them
    -->
    <Layout file="admin.main.cfm" name="admin">
      <Folder>admin</Folder>
    </Layout>
  </Layouts>

  <!--Internationalization and resource Bundle setup:

  <i18N>
    <DefaultResourceBundle>includes/main</DefaultResourceBundle>
    <DefaultLocale>en_US</DefaultLocale>
    <LocaleStorage>session</LocaleStorage>
    <UknownTranslation></UknownTranslation>
  </i18N>
  -->
  <i18N />

  <!--Datasource Setup, you can then retreive a datasourceBean via the
getDatasource("name") method:
  -->
  <Datasources>
    <!-- <Datasource alias="MyDSNAlias" name="real_dsn_name"
dbtype="mysql" username="" password="" /> -->
  </Datasources>

  <!--ColdBox Object Caching Settings Overrides the Framework-wide
settings -->
  <Cache>
    <ObjectDefaultTimeout>45</ObjectDefaultTimeout>
    <ObjectDefaultLastAccessTimeout>15</ObjectDefaultLastAccessTimeout>
    <UseLastAccessTimeouts>true</UseLastAccessTimeouts>
    <ReapFrequency>1</ReapFrequency>
    <MaxObjects>50</MaxObjects>
    <FreeMemoryPercentageThreshold>0</FreeMemoryPercentageThreshold>
    <EvictionPolicy>LRU</EvictionPolicy>
  </Cache>

  <!-- Interceptor Declarations
  <Interceptors throwOnInvalidStates="true">
    <CustomInterceptionPoints>comma-delimited list</

    <Interceptor class="full class name">
      <Property name="myProp">value</Property>
      <Property name="myArray">[1,2,3]</Property>
      <Property name="myStruct">{ key1:1, key2=2 }</Property>
    </Inteceptor>
    <Interceptor class="no property" />
  </Interceptors>
  -->
  <Interceptors>
    <!-- USE ENVIRONMENT CONTROL -->
    <Interceptor class="coldbox.system.interceptors.environmentControl">
      <Property name="configFile">/config/environments.xml.cfm</Property>
      <Property name='fireOnInit'>true</Property>
    </Interceptor>
    <!-- USE AUTOWIRING -->
    <Interceptor class="coldbox.system.interceptors.autowire">
      <Property name="enableSetterInjection">true</Property>
    </Interceptor>
    <!-- USE SES -->
    <!--
    <Interceptor class="coldbox.system.interceptors.ses">
      <Property name="configFile">config/routes.cfm</Property>
    </Interceptor>
    -->

  </Interceptors>

</Config>

Thanks.

I did not see anything obvious. You enabled the autowire interceptor, and your cfproperty declaration looks good.

Silly question, but, did you fwreinit?

Perhaps someone else will see something I have not.

Thanks. Yep, I fwreinit-ed.

So no one has any idea what's wrong?

I’m doing this very thing on Coldbox 2.6.4 on CF 9.0.1 and my settings are available in #variables.instance#.

Perhaps try creating a new very basic test example and see if you experience the same behavior. It should work using the information provided by others.

Jason Durham

Are you use ColdFusion Builder? If so I would set up your debugger and try
setting a break point and look into your variables, and see if it is
actually been injected. If it is not being injected then I would begin
looking into the way you are setting up the DI.

Regards,
Andrew Scott
http://www.andyscott.id.au/