[coldbox-4.1.0] Unable to access bean methods in RequestContext

Hi I am new to Coldbox and trying to understand the framework. I have reproduced beginning portion of RequestContext for the purpose of this question.

`

component serializable=false accessors=“true”{

/**

  • The request context
    */
    property name=“context” type=“struct”;

/**

  • The private request context
    */
    property name=“privateContext” type=“struct”;

/**

  • ColdBox Controller
    */
    property name=“controller”;

/**

  • ColdBox System Properties
    */
    property name=“properties”;

/************************************** CONSTRUCTOR *********************************************/

`

My observation is that properties are defined like ‘Controller’, but they will never be set. They are only set in Variables.instance structure. Therefore they are always empty. That is understandable.
But what is surprising me is that following code below results in property undefined:

`

`

My questions are:
1.why the bean getter property is undefined even though accessors is set to true
2.Why the those properties are defined when they will never be set and always empty. E.g output from following code:

`

`

displays:

Thanks in advance
Brahmaiah Koniki

Hello Brahmaiah , and welcome to ColdBox! You don’t need to know about the internal workings of the request context to use the ColdBox framework. However if you’re just a curious person and want to understand it better, then feel free to look around in the code.

> why the bean getter property is undefined even though accessors is set to true

Do you mean the bean getter method? I see the getProperties() and getController() methods in a cfdump of “event” in Lucee, but perhaps Adobe CF doesn’t show generated accessors in the metadata.

> Why the those properties are defined when they will never be set and always empty.

Good question. It appears those properties aren’t actually used. “Controller” is stored in “variables.instance” and “properties” isn’t stored at all. rc and prc are also in variables.instance. Honestly, those properties might have been for the API docs, or perhaps they just got left there on accident. I do know that starting with ColdBox 4, Luis wanted to move to using actual properties and generated accessors for bean properties rather than the simulated “instance” scope which is sort of a nod to Java. Obviously we didn’t get everything refactored over to that style, but it’s possible Luis started to refactor this CFC and never completed it.

Is there something you’re trying to do with ColdBox that you are having trouble with related to these variables? If you want the rc, call event.getCollection() and if you want prc, call event.getPrivateCollection(). I rarely ever call those methods though, since the rc and prc variables are automatically made available in all handlers, views, and layouts. If you want access to the controller in any view, layout, or handler, just call the getController() method that’s made available to you.

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 got it now. The statement set sets null value to variable ‘x’ and I trying to dump ‘x’ value through cfdump. It works fine with statement :

<cfdump var="#event.getController()#">

Also you are right, Lucee gives generated code also in cfdump. I started using Lucee now.

Thanks one again…

Regards
Brahmaiah Koniki

Do not use the event.getController() method as it looks like it’s there on accident. Just use getController() by itself in handlers, view, and layouts. If you need the controller in a model (service, bean, dao, etc) then ask WireBox to inject it for you with the following property:

component {
property name=“controller” inject=“coldbox”;
}

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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