Model Integration

Hi there

Its my first go with model integration...so be gentle..

Looking for some advice

I have a handler called artist which contains the following code (i
have stripped out erroneous code for the example)

<cfcomponent name="artist" extends="coldbox.system.eventhandler"
output="false" hint="all artist functions for site" autowire="true">

        <!---Dependencies--->
        <cfproperty name="mdl_artists" type="model" scope="instance" /

  <!---To display artists home page--->
  <cffunction name="home" access="public" returntype="void"
output="false" hint="displays an artists home page, with songs
listed">
   <cfargument name="EVENT" type="coldbox.system.beans.requestContext">

    <!---Reference to the request collection--->
     <cfset var rc=event.getCollection()>

     <!---Logic to Prepare View--->
           <cfset rc.qryArtData = instance.mdl_artists.getArtistData
(rc.name_art)>

    </cffunction>

          mdl_artists is my model object I am trying to inject into
the artist handler above

          However, I am getting the following error message when I
load the page....Element MDL_ARTISTS is undefined in a Java object of
type class [Ljava.lang.String;.

          Im sure im doing this completely wrong, but would like to
get a hang of model integration.

          Many thanks

1. Do you have the autowire interceptor declared in your
configuration? See "1. Configure the interceptor" in

http://ortus.svnrepository.com/coldbox/trac.cgi/wiki/cbAutowireGuide

2. Have you reinitialized the framework? When I add a new dependency
to an object, I sometimes get errors like that if I run the page after
adding the dependency. Reinitializing stitches it all back up
including my newly added dependency.

3. For pure troubleshooting purposes, try using an alternate way to call it.

<cfproperty name="mdl_artists" type="model:mdl_artists" scope="instance" />

4. If your model files are in a custom location, create a model
mapping "mdl_artists" that points to that custom location.

- Gabriel

Remember that handlers/plugins/interceptors need the autowire interceptor to be defined in the coldbox.xml.

Models are autowired automatically internally, no need to set autowire on them.

Ok,thanks for info..

I have done 1, 2 + 3 in your suggestions

But am now recieving an error message on my page, unsure what it
means..

Execution Exception
Error Type: Object : [N/A]
Error Messages: The containsBean method was not found.
Either there are no methods with the specified method name and
argument types, or the containsBean method is overloaded with argument
types that ColdFusion cannot decipher reliably. ColdFusion found 0
methods that matched the provided arguments. If this is a Java object
and you verified that the method exists, you may need to use the
javacast function to reduce ambiguity.

Presume that is saying that something is missing?

Thanks

Don't know what's causing that. If I was troubleshooting the full
code, I'd attack like this:

a. Reinitialize the framework. I always like to check that off the
troubleshooting list. If it still doesn't work....
b. Create a new handler with one event and one view and try to inject
something much simpler (like a configuration setting). Create a
request collection variable that equals the injected value and verify
in your view's debug panel that the value was created. Once that's
working....
c. Change the injected dependency to a model. Again, verify in your
view's debug panel that the model was properly injected. Once that's
working.....
d. Start to add parts of the real handler into the test handler. Add a
little at a time [making sure you reinit the framework when things go
wrong :-)] and you should end up with your test handler working with
all of your original code and the model integration.

- Gabriel

containsBean is only called when using an IoC framework integration, not model integration. Check if you have set one up or there any dependencies that have “ioc” in the type

Before I continue troubleshooting, would I need to have the setting
autowire="true" on the handler component, if I am injecting
dependancies from a model object?

I dont have any dependencies with ioc in the type....and have the
autowire inceterceptor set up like this

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

If you are injecting ANYTHING into handlers/plugins/interceptors, you need to mark them with autowire=true in the component tag.

In the autowire interceptor if you enable setter injection, then don’t use both cfproperty and setters, just use setters.

Luis

sorry for delay,

thanks for response....will soon try this method again, would really
like to get it working..

still getting the error

Element MDL_ARTISTS is undefined in a Java object of type class
[Ljava.lang.String;.

here...

Any ideas?

Thanks

Hi

Im not even sure how I would inject a config setting, and create a
request collection that equals an injected value..

Thanks

Hi there. I’m new to using CB’s model management aspect as well, but two things come to mind when looking at the error being thrown.

  1. Did you define the model object in your modelMappings.cfm file? It’s my understanding that if I want CB to manage a model item, I need to tell it about it via the modelMappings.cfm (I could be wrong on that though);
  2. Is it necessary to have defined “instance” in the constructor of the handler, as in putting “” just below the tag? In one example I saw of a model object having a bean injected via cfproperty, this was how it was being done, but in the handler example that bit of code wasn’t present. Wondering if it was just accidentally omitted from the example…

A couple of things to try, anyway.

Doug :0)

Thanks doug

Ok,

I have this code in my modelmappings.cfm

<cfscript>
  addModelMapping('mdlArtist','mdl_artists');
</cfscript>

Not sure if you are meant to have anymore code in the file than this?

I have then tried

<cfset variables.instance = structnew() />

OR

<cfscript>
instance=structnew ( );
</cfscript>

just below the cfproperty tag... <cfproperty name="mdlArtists"
type="model" scope="instance" />

But I am still recieving the error message "Element MDLARTISTS is
undefined in a Java object of type class [Ljava.lang.String;.", when i
load up the page

Hi,

I think you are trying things randomaly. Please have a coffee and
relax, read this guide.
http://ortus.svnrepository.com/coldbox/trac.cgi/wiki/cbModelGuide

Implement things step by step
Example:
<cfproperty name="mdlArtist" type="model:mdl_artists"
scope="instance">

You can access this object methods like this
instance.mdlArtist.getArtist();

Thanks
Sana

'Please have a coffee and relax, read this guide'

Invaluable advice!

I feel kind of silly now....just realised that the reason it wasnt
working was because I was using version 2.6.1 of coldbox where model
integration wasnt available..

Sorry for this, and thanks for your time

Namtax