How to get HelloWorld from Module with a Widget

Howdy,

I tried to get data from a module via a widget. Is that even possible?

currently I fail miserably :frowning:

My module in the modul_user folder looks like this:

`

testpanel
├── handlers
│ ├── base.cfc
│ └── Home.cfc
├── ModuleConfig.cfc
├── plugins
├── views
│ └── home
│ └── index.cfm
└── widgets
└── TestPanel.cfc

`

The TestPanel.cfc in the widgets folder contatins only some lines with code:

`

component extends=“contentbox.models.ui.BaseWidget” singleton{

testpanel function init(controller){
// super init
super.init(controller);

// Widget Properties
setName(“TestPanel”);
setVersion(“1.0”);
setDescription(“A widget that renders a the TestPanel Module”);
setAuthor(“Author”);
setAuthorURL(“https://www.author”);

return this;
}

any function renderIt(){

var content = runEvent(event=‘testpanel:Home.index’,eventArguments=arguments);
if( !isNull(content) ){
return content;
}

}

}

`

And the file handlers/Home.cfc:

`

component extends=“base” {

public void function index(event,rc,prc){
event.setView(view=“home/index”);
}

}

`

When I execute the code, I get every time following failure on the widget-page in the admin-area:

Error rendering widget: No matching function member [setView] for call with named arguments found, available function members are [asc,changeDelims,cJustify,compare,compareNoCase,deserializeJSON,each,every,filter,find,findNoCase,findOneOf,getToken,hasPrefix,hasSuffix,insert,isEmpty,lCase,left,len,listAppend,listAvg,listChangeDelims,listCompact,listContains,listContainsNoCase,listDeleteAt,listEach,listEvery,listFilter,listFind,listFindNoCase,listFirst,listGetAt,listIndexExists,listInsertAt,listItemTrim,listLast,ListLen,listMap,listPrepend,listQualify,listReduce,listRemoveDuplicates,listRest,listSetAt,listSome,listSort,listToArray,listValueCount,listValueCountNoCase,lJustify,ltrim,map,mid,reduce,reFind,reFindNoCase,REMatch,REMatchNoCase,removeChars,repeatString,replace,replaceNoCase,rEReplace,rEReplaceNoCase,reverse,right,rJustify,rtrim,some,spanExcluding,spanIncluding,stripCr,trim,uCase,ucFirst,wrap]

The frontend shows nothing.

Why do not I just get a hello world back from the View? It seems that I forget what …

Andy

Do you have code anywhere overriding the “event” variable to be something else. That error message sounds like the object you’re trying to call ‘setView()’ on is not the request context.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Hi Brad

I don’t think so. It’s Contentbox 3.0 installed and then this module with a widget.

I’ve uploaded the module in to dropbox:
https://www.dropbox.com/s/9z5upsfhdjgeepm/testpanel.tar.gz?dl=0

Perhaps you have time to look at that. Alternatively, I can also reinstall Contentbox.

Thank you in advance,

Andy

Do you have the stack trace to the error. I’d dump out the “event” variable and see what it is.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Of course: Stacktrace on Pastebin

When i Dump “event” on the widget-page, where you can test the widget, I get following:

I think the issue may be that you’re passing all of the arguments to renderIt in as event args. I think you may be overwriting the “event” argument in your handler call. What arguments coming into renderIt()?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Currently I’ve added nothing to renderIt(). I wanted to try just a simple HelloWorld :slight_smile:

According to the code in your original post, this is the contents of your renderIt() method:

any function renderIt(){

var content = runEvent(event=‘testpanel:Home.index’,eventArguments=arguments);
if( !isNull(content) ){
return content;
}

}

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Thats correct, should it be as follow?

any function renderIt(){

var content = runEvent(event='testpanel:Home.index");
if( !isNull(content) ){
return content;
}

}
(I removed eventArguments=arguments )

So runEvent Calls testpanel:home:index, which renders the View?

Sorry, but I’m just a messed up :frowning:

should it be as follow?

lol, I can’t tell you what you’re code is supposed to do :slight_smile:

If the event you’re calling needs those argument, then you might need it. If you don’t know that answer, then perhaps it can just be removed.

So, to be clear, when you removed the event args, are you still getting an error. Also, when you dump the arguments being sent to renderIt(), is there one called ‘event’?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

So, to be clear, when you removed the event args, are you still getting an error. Also, when you dump the arguments being sent to renderIt(), is there one called ‘event’?
The lines I have now been removed and the error has disappeared. Now it displays the following error:

Error rendering widget: The parameter data to function renderData is required but was not passed in. The parameter data to function renderData is required but was not passed in.

`
/**

  • Renders TestPanel form
    */
    any function renderIt(){
    var content = runEvent(event=‘testpanel:Home.index’);

if( !isNull(content) ){

return content;
}

}

`

A dump on the variable “content” trows following:

Not really sure without stack traces, but if you’re expecting your index action to return the HTML of the view, you can’t just do event.setView. You actually need to render the view right there with renderView() and return it.

return renderView( “home/index” );

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Brad, you are awesome - smile. It works and I now know how. Thank you!