Problem persisting a variable

This is probably a way newbie question, which is appropriate since I'm
still largely a newbie at CB. :slight_smile:

I have the following handler method:

    var rc = event.getCollection();
    var modelObj = getModel('client');
    var search = "";

    search = modelObj.searchPeople(
        obj:rc
      );

    setNextEvent( event='client.search_results', persist='search' );

I want the 'search' variable to be present in the following event.
When I get to that page, if I dump search, I get variable not
defined. If I dump rc, it's not in there either. What am I missing?
Do I need to do something in the handler method for
client.search_results?

Likewise, let's say I called the search service as rc.search =
searchPeople(), then tried to dump rc or rc.search in the handler... I
get the white screen of death in the browser (white page with no other
info). Any idea what that happens?

Thanks. :slight_smile:

Rob

Shouldn’t setNextEvent be…

setNextEvent( event: “client.search_results”, persist: search);

Jason Durham

The persist argument will look for the matching key in the request
collection. Search is not in the rc from your example.

If you switch it to

    var rc = event.getCollection();
    var modelObj = getModel('client');
    rc.search = "";

    rc.search = modelObj.searchPeople(
        obj:rc
      );

    setNextEvent( event='client.search_results',
persist='search' );

The variable should persist.

On your second problem. What is seachPeople() returning. I have seen
the white screen of death (coining that term for myself right now) when
attempting to dump a large object graph because CF chokes. Alternately,
I have seen this when caught in an infinite loop.

Hope this helps.

Curt Gratz
Computer Know How

I just tried persist=search (without quotes) and got an error
complaining that persist is not of type string.

Rob

Hi Rob,

setNextEvent takes string list of variables name to persist. Also
these persistent variables should be in RC scope.

Try this
rc.search = modelObj.searchPeople(
                                obj:rc
                        );
                setNextEvent( event='client.search_results',
persist='search' );

Now "search" variable is in RC scope then ColdBox will persist it for
you.

Thanks
Sana

So here's my latest code:

rc.search = modelObj.searchTalent(obj:rc);

setNextEvent( event='client.search_results', persist='search');

I paired down the line spacing for compactness here.

Anyway.. I'm still getting WSOD when trying this.

So next, I remove "rc." and make it just search. I then dump search in the handler. I see my results... which interestingly enough, LOOKS like a dump of rc, since I have keys of FORM, as well as my returned query (and it's whole 152 rows).

So that's when I continue to have persist='search' and leaving rc.search off entirely, but then at the next event, 'search' isn't defined.

So if I try to persist any form of rc, I get WSOD. If I don't use rc, I don't get any data.

Weird.

This is on OSX 10.6.4 CF901 and CB 2.6.4.

Rob

BINGO.

WhyYou know what the problem was?

var data = "";

and then my call was

data = modelObj.searchPeople(whatever);

When I changed data = "" to data = structNew() all worked.

So the final result is below:

var rc = event.getCollection();
var modelObj = getModel('client');
var data = StructNew();

data = modelObj.searchPeople(
    obj:rc
  );

event.setValue("search", data);
setNextEvent(event='client.search_results', persist='search');

And then in the search_results method:

var rc = event.getCollection();
event.getValue("search");
event.setView("client.search_results");

So hopefully this will help others who encounter this situation.

Rob

WhyYou know what the problem was?

var data = "";

and then my call was

data = modelObj.searchPeople(whatever);

When I changed data = "" to data = structNew() all worked.

That makes no sense, you know?

var rc = event.getCollection();
var modelObj = getModel('client');
var data = StructNew();

data = modelObj.searchPeople(
obj:rc
);

Since you're overwriting data on the next line, you could set it to
*any* value at all and it would have no effect whatsoever. You could
also do this instead (which would be better):

var rc = event.getCollection();
var modelObj = getModel('client');
var data = modelObj.searchPeople(
               obj:rc
       );

You don't want to set rc.search = ""; on the line above the call -
it'll end up being passed into searchPeople() as part of the obj
argument. Try this:

               var rc = event.getCollection();
               var modelObj = getModel('client');
               rc.search = modelObj.searchPeople(
                               obj:rc
                       );

               setNextEvent( event='client.search_results', persist='search' );

I agree, it makes no sense. But the way I discovered it was by creating an empty struct, adding a few keys to it with strings, and then adding my ‘data’ variable to it. That worked, and that’s when I went DUH!!!

I think it would have been fine outside of the framework, but yeah, Coldbox choked on it.

Rob

I just ran into an issue where the Flash object is not working as it
did in M5.

Here is my example event handler code that proved I was not crazy (at
least, not yet). When I run it, the variable 'CAT' does not appear in
the request collection. Nothing has changed in the environment. I am
using session for my relocation.

/** Redirects to B */
function A (Event) {
  rc.cat = 'Padme';

  // This worked in M5
  Flash.persistRC('cat');

  // Tried This too
  Flash.put(name='cat',value=rc.cat,inflateToRC=true,keep=true);

  // Redirect
  setNextEvent('B');
}

I came to this group to see if anyone else had an issue, and, it looks
like something may have changed with the Flash persistence with M6.
I'll start looking into the source.

Turns out, someone did modify a setting in our Application.cfc

<cfset this.setClientCookies = false />
should be
<cfset this.setClientCookies = true />

to use the session or client flash storage scopes.

Thanks,

Aaron

Very sneaky sneaky, aaron, do you have access to the wiki docs?

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

They aren’t setting them in the onSessionStart method are they? I’ve seen this done to make cookies expire when the browser closes. The session or client flash storage scopes should still work that way.