Simple Question Regarding RC Behavior

43 views
Skip to first unread message

Rodney

unread,
Oct 25, 2018, 1:59:42 PM10/25/18
to framework-one
I apologize if this has been answered before, but I can't seem to find anything.  I'm writing some code that would need to pass an instantiated bean from one controller method to another.  I'm calling getBean() and setting it equal to a variable in RC.  As a test, I'm also making another variable in RC that just holds a string.  The following code perfectly illustrates my problem:

Application.cfc
component extends=framework.one {
   
}

controllers/main.cfc
component accessors="true" {
   property framework;
   property beanFactory;

    public function default( struct rc ){
       if(!structKeyExists(rc, "testing")){
          rc.testing = variables.beanFactory.getBean('testBean');
       }  

        if(!structKeyExists(rc, "testVariable")){
           rc.testVariable = "Testing Starting!";
        }
       
       rc.testing.setTestOne("Here!");
   }

    public function test( struct rc ){
       rc.testing.setTestTwo("Here!");
       rc.testVariable = "Testing Over!";
   }

}

models/beans/testBean.cfc
component accessors="true" {
   property testOne;
   property testTwo;

    public testBean function init(){
       testOne = "Missing!";
       testTwo = "Missing!";
       return this;
   }
}


view/main/default.cfm
<p>Main</p>

<cfoutput>
   <p><a href="#buildURL('main.test')#">Proceed to test...</a></p>
</cfoutput>

<cfdump var="#rc#">

view/main/test.cfm
<p>Test</p>

<cfoutput>
   <p><a href="#buildURL('main.default')#">Proceed back to main...</a></p>
</cfoutput>

<cfdump var="#rc#">

test.cfm errors out whenever I try to access it, stating that element Testing does not exist in RC if I have rc.testing.setTestTwo("Here!");  uncommented in the controller..  If I have it commented out, then I can access test.cfm, but I can't see the testing variable in RC in cfdump, and when I follow the link back to default.cfm, cfdump shows the string variable inside RC is reset instead of showing the new value, indicating that RC is being recreated instead of being passed between methods.

I'm a bit reluctant to post this, as I'm just learning CFML and FW/1 and the answer is most likely trivial, but I can't seem to find it in the documentation on the FW/1 website, and the github examples I'm browsing don't appear to address the issue or aren't using DI/1 to manage their beans.  My understanding is that structs are passed by reference in methods, but even if it was being passed by value, I should still see the variables I've declared in the previous function, so RC is behaving rather odd to me.  What am I misunderstanding?

Rodney

unread,
Oct 25, 2018, 2:13:01 PM10/25/18
to framework-one
I forgot to mention that I'm using ColdFusion 2018 Developer Edition, but I'm also seeing this on ColdFusion 2016, as well.

Richard Tugwell

unread,
Oct 25, 2018, 2:18:34 PM10/25/18
to framew...@googlegroups.com
As far as I remember (it's been a while) FW1 won't look for a default() method and execute it, so when you call /main/test it will only execute /main/test() (and associated views/layouts)

--
FW/1 documentation: http://framework-one.github.io
FW/1 source code: http://github.com/framework-one/fw1
FW/1 chat / support: https://gitter.im/framework-one/fw1
FW/1 mailing list: http://groups.google.com/group/framework-one
---
You received this message because you are subscribed to the Google Groups "framework-one" group.
To unsubscribe from this group and stop receiving emails from it, send an email to framework-on...@googlegroups.com.
Visit this group at https://groups.google.com/group/framework-one.
For more options, visit https://groups.google.com/d/optout.


--
=================================
Richard Tugwell
r.tu...@forthmedia.com

Richard Tugwell

unread,
Oct 25, 2018, 2:19:22 PM10/25/18
to framew...@googlegroups.com
.. and so rc.testing won't exist

Richard Tugwell

unread,
Oct 25, 2018, 2:21:12 PM10/25/18
to framew...@googlegroups.com
NB I think the slack channels are the best place to get FW1 help these days (fw1.slack.com I think)

Richard Tugwell

unread,
Oct 25, 2018, 2:23:15 PM10/25/18
to framew...@googlegroups.com
Actually that group may not be correct, but I only have phone access atm

Richard Tugwell

unread,
Oct 25, 2018, 2:24:53 PM10/25/18
to framew...@googlegroups.com

Rodney Favignano

unread,
Oct 25, 2018, 2:33:29 PM10/25/18
to framew...@googlegroups.com
Thanks for your help, and I'll post questions there in the future! 

So when I call main.default in main/test.cfm, it won't look for default() in the controller and execute it?  The output from main/default.cfm seems to indicate that it's seeing rc.testVariable and rc.testing, but the values are what I would expect them to be had I not visited main/test.cfm at all, and if I try to change the value of one of the variables in my bean in test(), it throws up an error saying the variable holding the reference to my bean doesn't exist.  Sorry if I wasn't clear in my previous post - it looks like default() is executing, but when I go to test.cfm, the code acts like it just tosses rc out of the window and declares a new struct called rc.

You received this message because you are subscribed to a topic in the Google Groups "framework-one" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/framework-one/9cEm5maYlkY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to framework-on...@googlegroups.com.

Richard Tugwell

unread,
Oct 25, 2018, 2:38:00 PM10/25/18
to framew...@googlegroups.com
When you go to main/test RC structure is completely new - it's a new request. It knows nothing about anything that happened in main/default. When you go to main/default it is setting rc.testVariable and rc.testing so those will be available in the view

Richard Tugwell

unread,
Oct 25, 2018, 2:38:35 PM10/25/18
to framew...@googlegroups.com
It's not like, for example Angular routing

Sean Corfield

unread,
Oct 26, 2018, 12:05:46 PM10/26/18
to framew...@googlegroups.com

So when I call main.default in main/test.cfm, it won't look for default() in the controller and execute it?

 

You are not “calling” main.default in main/test.cfm. buildURL() just builds a URL from an action name – it doesn’t execute the action (that would be chaos since every link on your page would be trying to execute code!).

 

Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

 


From: framew...@googlegroups.com <framew...@googlegroups.com> on behalf of Rodney Favignano <rfavi...@gmail.com>
Sent: Thursday, October 25, 2018 11:33:15 AM
To: framew...@googlegroups.com
Subject: Re: [framework-one] Re: Simple Question Regarding RC Behavior
 

Richard Tugwell

unread,
Oct 26, 2018, 12:15:49 PM10/26/18
to framew...@googlegroups.com
@rodney - depending on your use-case you could possibly leverage the before() method in a controller - however bear in mind that this is run before every method.

Sent from my iPhone
Reply all
Reply to author
Forward
0 new messages