[Coldbox 4.1] Include renderer in model CFC

Hi,

We are porting our web app from Coldbox 3 to Coldbox 4. All is working fine except for the include of the renderer we are using in one of our models.
According to the documentation we should be able to include it like this:

However the following error occurs:

Railo 4.2.1.008 Error (Injector.InstanceNotFoundException)
Message Requested instance not found: ‘Renderer@coldbox’
Detail The instance could not be located in any declared scan location(s) (models) or full path location
Stacktrace The Error Occurred in
C:\Projects\mailService\coldbox\system\ioc\Injector.cfc: line 237

235: throw(message=“Requested instance not found: ‘#arguments.name#’”,
236: detail=“The instance could not be located in any declared scan location(s) (#structKeyList(instance.binder.getScanLocations())#) or full path location”,
237: type=“Injector.InstanceNotFoundException”);
238: }
239: // Let’s create a mapping for this requested convention name+path as it is the first time we see it

called from C:\Projects\mailService\coldbox\system\web\Controller.cfc: line 124
called from C:\Projects\mailService\coldbox\system\ioc\dsl\ColdBoxDSL.cfc: line 90
called from C:\Projects\mailService\coldbox\system\ioc\dsl\ColdBoxDSL.cfc: line 38
called from C:\Projects\mailService\coldbox\system\ioc\Builder.cfc: line 332
called from C:\Projects\mailService\coldbox\system\ioc\Injector.cfc: line 603
called from C:\Projects\mailService\coldbox\system\ioc\Injector.cfc: line 490
called from C:\Projects\mailService\coldbox\system\ioc\scopes\RequestScope.cfc: line 44
called from C:\Projects\mailService\coldbox\system\ioc\Injector.cfc: line 261
called from C:\Projects\mailService\coldbox\system\ioc\config\Binder.cfc: line 917
called from C:\Projects\mailService\coldbox\system\ioc\Injector.cfc: line 157
called from C:\Projects\mailService\coldbox\system\ioc\Injector.cfc: line 92
called from C:\Projects\mailService\coldbox\system\web\services\LoaderService.cfc: line 104
called from C:\Projects\mailService\coldbox\system\web\services\LoaderService.cfc: line 50
called from C:\Projects\mailService\coldbox\system\Bootstrap.cfc: line 71
called from C:\Projects\mailService\coldbox\system\Bootstrap.cfc: line 107
called from C:\Projects\mailService\coldbox\system\Bootstrap

So I’m probably doing something wrong but I cannot find what. Any help is appreciated!

Do you have that module installed?​

Well the documentation says this: “The renderer still exists, but not in plugin form. It has become a core part of the framework.” so I should not install the module seperately right?

Ok, might have to wait for one of the others then. I knew it was removed, but I assumed it was a module now.

Ok, thanks for looking. :slight_smile:

There might be a better solution then using a renderer for what I’m trying to do but I have not found. Basically I’m using a cfmail tag in my model to send a mail, and use a renderer to render the body of the mail:

`

#renderer.renderView(view=“mailtemplates/#arguments.languageCode#/#arguments.mailType#”, args=data)#
<cfif structKeyExists(arguments,‘attachment’) and arguments.attachment neq ‘’>


`

Something like this?

var content = arguments.comment.getRelatedContent();
// get subscribers for this content item
var subscriptions = content.getCommentSubscriptions();
var settings = settingService.getAllSettings( asStruct=true );
var commentAuthorEmail = arguments.comment.getAuthorEmail();
// get body tokens; can reuse most for all emails
var bodyTokens = arguments.comment.getMemento();
bodyTokens[ “contentURL” ] = CBHelper.linkContent( content );
bodyTokens[ “contentTitle” ] = arguments.comment.getParentTitle();
// loop over subscribers
for( var subscription in subscriptions ) {
var subscriber = subscription.getSubscriber();
// don’t send email if the comment author is also subscribed…
if( subscriber.getSubscriberEmail() != commentAuthorEmail ) {
// get mail payload
bodyTokens[ “unsubscribeURL” ]= CBHelper.linkContentUnsubscribe( subscription.getSubscriptionToken() );
// Send it baby!
var mail = mailService.newMail(to=subscriber.getSubscriberEmail(),
from=settings.cb_site_outgoingEmail,
subject=“New comment was added”,
bodyTokens=bodyTokens,
type=“html”,
server=settings.cb_site_mail_server,
username=settings.cb_site_mail_username,
password=settings.cb_site_mail_password,
port=settings.cb_site_mail_smtp,
useTLS=settings.cb_site_mail_tls,
useSSL=settings.cb_site_mail_ssl);

var args = { gravatarEmail= commentAuthorEmail };
// generate content for email from template
mail.setBody( renderer.get().renderLayout(
view="/contentbox/email_templates/comment_notification",
layout=“email”,
module=“contentbox-admin”,
args = args
));
// send it out
mailService.send( mail );
}
}

I have been able to make it work by getting the renderer in my handler with: getController().getRenderer() . Weird that it doesn’t seem to be working with the inject.

Yea, even the snippet I showed you use the DI of the renderer. I am guessing you did do a fwreinit on any changes to the model?

Indeed, always used fwreinit.

kk, maybe there was some other reason it isn’t being injected. Have you tried switching on the logs to see if they have any clue. You will need to make sure you have error level though.

Are you using ColdBox 4.1?

4.1 introduced it. You can either do

DSL

  • coldbox:renderer
    ID
  • Renderer@coldbox
    Manually
  • getController().getRenderer()

Luis Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com
P/F: 1-888-557-8057
Direct: (909) 248-3408

ColdBox Platform: http://www.coldbox.org

ContentBox Platform: http://www.gocontentbox.org
Linked In: http://www.linkedin.com/pub/3/731/483

Social: twitter.com/ortussolutions | twitter.com/coldbox | twitter.com/lmajano | twitter.com/gocontentbox