I've gotten my head around my first Model Glue app, except one thing - Global 
variables.

I googled and googled, and used some examples, but still having no luck. 

Model Glue 2.0.304 - Running into an error. 

My goal is to set a simple DSN global variable that I can use anywhere. I've 
used some examples from Googling, but still
can't make anything work. 

Coldspring.xml looks like this:

<bean id="AppConfiguration" class="ModelGlue.Bean.CommonBeans.SimpleConfig">
   <property name="Config">
     <map>
      <entry key="DSN"><value>leroy</value></entry>
     </map>
   </property>
</bean>

<bean id="Employee" class="model.Employee">
  <constructor-arg name="AppConfiguration">
     <ref bean="AppConfiguration" />
      </constructor-arg>
</bean>

I have my controller object, which does not use an init():

<cffunction name="showEmployees" access="public" returnType="any" 
output="false">
  <cfargument name="event" type="any" />

   <cfscript>
    var Employee = createObject("component", "model.Employee").init();
    var getEmployees = Employee.getEmployees();
   
    arguments.event.setValue("employees", getEmployees);
   </cfscript>
</cffunction>

I built an Employee object. The Employee object uses an init(), and simply runs 
a query and returns all employees. 

<cffunction name="init" access="public" returntype="Employee" output="no">
  <cfargument name="AppConfiguration" required="true" />

    <cfset variables.config = arguments.AppConfiguration />
      
 <cfreturn  this />
</cffunction>


Then here's the query:

<cffunction name="getEmployees" access="public" returnType="query" 
output="false">

    <cfscript>
     var getEmployees = ""; 
     var myDSN = variables.config.getConfigSetting("DSN");
    </cfscript>

      <cfquery name="getEmployees" datasource="#myDSN#">
      select emp_id, emp_fname, emp_lname, emp_age
      from tblemployees
      </cfquery>
  <cfreturn getEmployees />
</cffunction>


The error is coming from this line in the controller:

var Employee = createObject("component", "model.Employee").init();

Error:

The APPCONFIGURATION parameter to the init function is required but was not 
passed in.
 
The error occurred in C:\webRoot\MG-ComplexData\controller\Controller.cfc: line 
77

I'm assuming Employee.cfc is automatically init()ing when the app loads, so I 
shouldnt need to init() it 
again. I'm fuzzy...

If I take the init() off the controller call like this:

var Employee = createObject("component", "model.Employee"); 

Then I get this error:

Element CONFIG is undefined in a Java object of type class [Ljava.lang.String;.
 
The error occurred in C:\webRoot\MG-ComplexData\model\Employee.cfc: line 82

Thanks,
Will 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;203748912;27390454;j

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:307848
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to