external model and getModel().init()

Trying to catch up with CB3, and to see if i can get external models
work besides the convention model directory, but I got this error.

Error constructing model: MySample
The MYSAMPLEINFO parameter to the init function is required but was
not passed in...

have spent some of time on this, and can’t figure it out.

Here is my handler,
....
local.myBrowser = getModel('MySample').init("mysqmpleinfo") ;
modelMappings.cfm
addModelMapping(path="/common/models/MySample");
....
coldbox.cfc
models = {
    objectCaching = true,
    definitionFile = "config/modelMappings.cfm",
    externalLocation = "common.models",
    SetterInjection = false,
    DICompleteUDF = "onDIComplete",
    StopRecursion = ""
};
....

MySample.cfc
....
<cffunction name="init" access="public" returntype="MySample"
output="false" hint="Constructor">
    <cfargument name="mySampleInfo" type="any" required="true">
    <cfscript>
   this.setMySampleInfo(arguments.mySampleInfo);
  return this;
</cfscript>
</cffunction>

1. Is this the only way for external shared models?
2. MySample.cfc has an init() with a required argument. Is the
getModel('MySample').init("getMySampleInfo()") a correct syntax?

Thanks for any help on this!
-Tony

I don't think this is the problem, but I believe that this

addModelMapping(path="/common/models/MySample");

should be

addModelMapping(path="MySample");

If you read the documentation it says that you don't need the conventions in
the path, as the path is from the convention path.

As for the problem, my guess would be that you are autowiring the model
somewhere in your application.

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

Hi Andrew,

Thanks for your prompt response.
The MySample.cfc is outside of the convention “model” directory,that
is why i did addModelMapping(path="/common/models/MySample"); but the
problem is that an error is thrwon on passing param into the init()...

I am trying to found if CB can have an external model directory? I am
still learning about the DI and model autowiring stuff, and I should
not have any autowiring in the application or at least don't intent
to. Indeed, this is a very simple testing application for my learning
purpose(I tried CB sometime ago, and now come back to see if I can
grasp it better… =); it has only one handler, one ample cfc…

Not sure if it makes any sense to you.

Again, thanks,
-Tony

could it be a bug? i am passing the init function a value, but still
got the error...

coldbox\system\plugins\BeanFactory.cfc : line 237
The MYSAMPLEINFO parameter to the init function is required but was
not passed in.

actually, what i want is to have a shared external model directory
which is different directory as the convertion model folder?

am i missing anything? and thanks for any suggestions!

Tony

In your config.cfc you have this

externalLocation = "common.models",

This is mapping the location, and is why I suggested removing the path back
to its roots. I am aware that error is telling you that it is not passing
something in, and I am thinking that somewhere you either have you bean.cfc
setup incorrectly or you hare trying to inject it somewhere.

If you are using property name='something' inject='model.mySample' this
doesn't pass anything into the init and will throw this error. And I am
almost 99.99% positive that this is the problem.

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

From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of TH
Sent: Monday, 27 September 2010 10:26 AM
To: ColdBox Platform
Subject: [coldbox:5925] Re: external model and getModel().init()

Hi Andrew,

Thanks for your prompt response.
The MySample.cfc is outside of the convention "model" directory,that is

why

i did addModelMapping(path="/common/models/MySample"); but the
problem is that an error is thrwon on passing param into the init()...

I am trying to found if CB can have an external model directory? I am

still

learning about the DI and model autowiring stuff, and I should not have

any

autowiring in the application or at least don't intent to. Indeed, this is

a very

simple testing application for my learning purpose(I tried CB sometime

ago,

and now come back to see if I can grasp it better. =); it has only one

handler,

Another thing, when you call getModel(), this calls automatically the “init()” constructor.

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Thanks much Andrew and Luis,

The templates have been used for testing and are kind of messy.
After I cleaned it up, and it seems work ok now on CreateObject
without using the getModel().init(), which is still not so clear to me
=)

Luis, "...when you call getModel(), this calls automatically the
"init()" constructor." but how we can pass a value if the init() has a
required param?

And if you don't mind i would like to ask you two more questions. I
like it much all the CB tools and flexibility, but not sure

1. if the CB application starting time can be reduced in a production
environment? (it takes too long to reinitialize framework every time
even with a very simple event)

2. not planning to have the stuff such as Dependency Injection,
autowiring and etc, but all those related functions/coding will be
still running. Do you think that will drag down the performance of the
CB application? can those features be bypassed or disabled.

Again thanks,

-Tony

Tony,

In production you would have a different set of config settings, usually to
cache things somewhat. To give you an idea on my machine at home with debug
and no caching I can render a page in about 5-10 secs (Due to the large
amount of structs in rc) But as soon as it goes to production I am running
in around 200ms-500ms depending on the page.

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

From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of TH
Sent: Monday, 27 September 2010 4:05 PM
To: ColdBox Platform
Subject: [coldbox:5936] Re: external model and getModel().init()

Thanks much Andrew and Luis,

The templates have been used for testing and are kind of messy.
After I cleaned it up, and it seems work ok now on CreateObject without
using the getModel().init(), which is still not so clear to me
=)

Luis, "...when you call getModel(), this calls automatically the "init()"
constructor." but how we can pass a value if the init() has a required

param?

And if you don't mind i would like to ask you two more questions. I like

it

much all the CB tools and flexibility, but not sure

1. if the CB application starting time can be reduced in a production
environment? (it takes too long to reinitialize framework every time even
with a very simple event)

2. not planning to have the stuff such as Dependency Injection, autowiring
and etc, but all those related functions/coding will be still running. Do

you

Thanks Andrew for the insight.

and Luis, i may be slow on this but i am still trying to figure out
how getModel() work...

you said "...when you call getModel(), this calls automatically the
"init()" constructor." my question is if a required param can be taken
by the init() ?

i am reading the CB BeanFactory.cfc, and if i am not wrong here is the
block of the code to handle the getModel(). and from what i read so
far, an obj will be init()ed but without taking in any params. am i
missing anything here?
...
// Create the model object
oModel = createObject("component", modelClassPath);
//If we are to execute the init() constructor, then do it.
if ( arguments.executeInit ) {
  // Verify Constructor: Init() and execute
  if( structKeyExists(oModel,"init") ){
   try{
     oModel.init(argumentCollection=getConstructorArguments(oModel));
   }
    catch(Any e){
....

-Tony

http://wiki.coldbox.org/wiki/Models.cfm#getModel()

Here, you can see that getModel supports an argument called initArguments. It’s a struct, and looks like more or less of a passthrough to the constructor. The original issue you are facing with getModel().init(‘foo’) is that the error is thrown inside getModel - with its own init call - before you ever get to your own .init(‘foo’) call. Note: haven’t actually tried this yet, but it looks like that’s what initArguments is there for.

best