setNextEvent(persist={}) Saves Twice

I’m writing an interface to the FlashScope and noticed two records were being inserted. Tracing back through the system I discovered ColdBox is saving the FlashScope twice. Once when the “persistVariables()” method is called within the Controller and again right before the redirect.

Is this the desired behavior?

// WHEN SETNEXTEVENT() IS CALLED
project\core\model\FlashScope.cfc:107)
coldbox_fork\system\web\flash\AbstractFlashScope.cfc:202)
coldbox_fork\system\web\Controller.cfc:650) <<<<<< putAll(map={},saveNow=true);
coldbox_fork\system\web\Controller.cfc:437)
coldbox_fork\system\FrameworkSupertype.cfc:235)
project\core\includes\UDF.cfm:39)
project\gui\handlers\Login.cfc:99)

// JUST BEFORE REDIRECT
project\core\model\FlashScope.cfc:107)
coldbox_fork\system\web\Controller.cfc:448) <<<<<< saveFlash();
coldbox_fork\system\FrameworkSupertype.cfc:235)
coldbox_fork\system\web\Controller.cfc:704)
coldbox_fork\system\web\Controller.cfc:591)
coldbox_fork\system\Coldbox.cfc:243)

Thanks,

Aaron

Actually, I made a mistake in my previous message.

I am not providing the persist argument to setNextEvent().

I only call…
Flash.put(name=‘UserErrors’,value=rc.User.getMemento(‘errors’));

But, two calls are being executed.

Here is the caveat on this.

We introduced the flash interface in 3.0, before it was just via the persistVariables() method and the persist arguments on relocations. For backwards compatibility, those two approaches are still valid, but they save the variables IMMEDIATELY to reflect behavior as it was before.

Now, on relocations, is when we automatically trigger the saveNow() on the flash scope for you. However, if you are not relocating but just setting data on the flash scope and then rendering a page, you will need to call save explicitly.

Hopefully, by 3.1 we can remove the persistVariables() method, as our preferred approach is via the flash object.

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