[ColdBox MVC + ORM] Passin along a message to the next event

I am getting to grips with Coldbox, so please bear with me as I get a grib on the basics.

I am trying out a very simple scenario with the framework, a CRUD for a PATIENT user object. Upon saving, I want to set a message (for now just something generic like “Successful”, and then pass that along to the LIST event, so that it displays that somewhere above the renderView(). I tried to persist the prc, the prc.message but I can’t get it to work. Also, I have seen a plugin called MessageBox, if I am not wrong, which may only come with ColdBox - can I use that and perhaps an example?

Here is my patient.cfc handler (I use the INDEX function name to be the entry point which then points to another event to make it simpler to switch to something else in the future - something taken from Grails). I set a prc.message inside the SAVE event and I want to pass that along to the INDEX, which then gets passed to the LIST.

`
component{

property name=“patientService” inject=“entityService:patient”;

function index(event,rc,prc){
setNextEvent( event=“patient.list” );
}

function list(event,rc,prc){
prc.patients = patientService.list( sortOrder=“lastName”, asQuery=false );
}

function save(event,rc,prc){
event.paramValue( “patientID”, 0 );
patientService.save( populateModel( patientService.get( rc.patientID ) ) );
prc.message = “Saved successfully!”;
setNextEvent( event=“patient” );
}

function add(event,rc,prc){
event.paramValue( “patientID”, 0 );
prc.patient = patientService.get( rc.patientID );
prc.pageTitle = “Add New”;
event.setView( “patient/edit” );
}

function edit(event,rc,prc){
event.paramValue( “patientID”, 0 );
prc.patient = patientService.get( rc.patientID );
prc.pageTitle = “Edit”;
event.setView( “patient/edit” );
}

function delete(event,rc,prc){
event.paramValue( “patientID”, 0 );
patientService.deleteByID( rc.patientID );
setNextEvent( “patient” );
}

}
`

And here’s where I add it to my layout:

`

#prc.message#
#renderView()#

`

Am I even going about this the right way?

Hi Evagoras,

You can use the “persist” argument in your setNextEvent method call. It allows you to specify which request collection values you want to persist into the the next request (it’s stored in the FLASH ram and made available into the next request by the framework).

function save(event,rc,prc){
event.paramValue( “patientID”, 0 );
patientService.save( populateModel( patientService.get( rc.patientID ) ) );
prc.message = “Saved successfully!”;
setNextEvent( event=“patient”, persist=“message” );
}

I have tried that, but I can’t get it to work. I tried this:

setNextEvent( event="patient.list", persist="message" );

even this:

setNextEvent( event="patient.list", persist="prc" );

and even this:

setNextEvent( event="patient.list", persist="prc.message" );

but when I dump the rc or the prc arguments in the next event I get nothing (which one is it going to go into?). I am chaining 2 events in my case upon saving, so is that the reason - meaning that my SAVE calls the INDEX, which calls the LIST event (look at my code above).

The correct syntax is the first one you listed:

setNextEvent( event=“patient.list”, persist=“message” );

But I just noticed you are using **prc.**message (private request collection), I always persist against the values in the rc “scope”, can you try changing **prc.**message to **rc.**message and then do the persist=“message” in the arguments and dump both of them in the next event view. I do this all the time (similar success/fail message use case you are trying to do) and it works… I’m wondering if private request collection is not made to be persisted, only the regular request collection. Let me know if that works.

Good luck. :slight_smile:

I changed it to what you suggested, but I still get nothing. This is what my handler looks like now:

`

function list(event,rc,prc){
writeDump(prc);
writeDump(rc);
prc.patients = patientService.list( sortOrder=“lastName”, asQuery=false );
}

function save(event,rc,prc){
event.paramValue( “patientID”, 0 );
patientService.save( populateModel( patientService.get( rc.patientID ) ) );
rc.message = “Saved successfully!”;
setNextEvent( event=“patient.list”, persist=“message” );
}

`

But all I get in the dumps is:

Is there perhaps a setting I need to change to enable this “flash” persistence?

try flash.put() & get()

Aha, that leads to an exception when I try the flash.put():

`

`

So, is that because I need to enable the flash persistence somewhere in the framework?

i dont think so. ive never used settings for flash but have used it.

maybe you have settings that disable it. or put the flash somewhere where it isnt persisting.

or accessing the flash before its created. is this app in dev mode?

Can you confirm there’s only a single redirect happening with your browser’s network tools? Flash vars are only persisted for one redirect, but if you’re using something like the SSL interceptor that’s bouncing you from HTTP to HTTPs it could be getting lost along the way.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

This is all new to me, so I am not sure if I have any settings that disable that. I am basically using the Contacts sampler from the download.

Looking through the docs, I see that the DEV mode is enabled in the “/config/Coldbox.cfc” through a “settings” struct, and I have nothing there. There is some code from the example, but it’s commented out, so I don’t think that’s it either.

is your flash using session variables? if so, do you have sessions enabled?

settings:

flash = {
	scope = "session,client,cluster,cache,or full path",
	properties = {}, // constructor properties for the flash scope implementation
	inflateToRC = true, // automatically inflate flash data into the RC scope
	inflateToPRC = false, // automatically inflate flash data into the PRC scope
	autoPurge = true, // automatically purge flash data for you
	autoSave = true // automatically save flash scopes at end of a request and on relocations.
};

@Brad:
I just checked and there is only one redirect happening. No switch between SSL and non-SSL.

@Aaron:
I just read through the documentation for the Coldbox Lite MVC and ORM (http://wiki.coldbox.org/wiki/Cbl.cfm) and it says that Flash RAM is NOT included with the LITE framework. That’s probably why it doesn’t work. :slight_smile:
However, how then do I persist messages from one event to another?

My bad for not specifying what version I am using:
coldboxLITE-ORM_1.2.0

i would write a simple plugin.

i wonder if you can ala carte items into cb lite.

If I were you, I would just start using the ColdBox Platform. It appears you’re already finding out how useful its tools can be. The MVC conventions between the ColdBox Platform and ColdBox LITE are identical. The difference is simply that you have all the good stuff to use as well.

To answer your questions specifically, you can simply set things into the session scope manually.

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:
Since ideally I want to stay away from sessions as I learn the framework (we try to keep clusters of CF servers at work with no sessions enabled), I think I am going to take your advice and switch to the full framework. Besides, like you said, I don’t want to be reinventing the wheel as I am learning.

Thanks Aaron and Brad!

Brad, what makes cb lite truly light? init times?

i mean, once a framework is in memory, its just that… in memory.

better question, if there isnt a performance difference, why use cb lite w/o the goodies.