Output flash key/value in same event it was declared event, rather than next event

I know I can do this, but just can’t find in any of the docs where.

I have the following lines of code in an action if a model doesn’t save:

`
flash.put(‘danger’,‘There was a problem posting the Advertisement. Please check the information you are attempting to submit and try again.’);

return renderView(“employmentads/new”);
`

In my employmentads/new view, I need the flash to output, but of course it doesn’t as it won’t until the next event.

Can anyone tell me how I get flash to become current for the current event, rather than waiting till the next? As mentioned, I know I have seen somewhere that this can be done, but just can’t find anywhere.

Thanks!

Jason

Could you not add this to the Private Request Context for that view, or is the view being used elsewhere as well?

Flash.get Should work

Hi Andrew, the logic that is to access the Flash is actually in the layout. I have the following code in my layout to render out any flash notices that may exist

`

#flash.get(flashKey)#

`

So when I complete an action, I can save a message to the flash, the flow goes to the next event and the flash message is displayed to the user.

In some cases, where (as in this case) there was a problem handling a users form submission, I want to show them the form, populated with what they submitted, and an error message via the flash. The problem is, as I am rendering the view as part of the current action, the flash does not get rendered. To do this, I need some way of telling the flash to render in the same event it is declared in, rather than waiting for the next event.

I thought I had read somewhere about some setting in the flash, but maybe I dreamt it…

Thanks again

Jason

I also meant to post my action flow to show what I am doing there as well, as this may explain better what I am trying to acheive.

`

rc.savedAd = adService.saveItem(argumentcollection=rc);

if (isObject(rc.savedAd)){

flash.put(‘success’,‘Your Submissions has been sent and will be reviewed shortly.’);

setNextEvent(url=’/index.cfm/#event.getCurrentRoutedURL()#?e=_employmentads.confirmsaved’);

} else {

flash.put(‘success’,'There was a problem posting the Advertisement. ');

rc.ad = orm.populate(orm.new(“EmploymentAd”),rc);

return renderView("_employmentads/new");

}

`

Thanks Guys!

Wouldn’t the messagebox be better suited for error messages?

With the flashput you could have used inflatetoprc, then in the view you could have used the prc and only use the flash in the setnextevent if the messagebox doesn’t work.

Or you could pass in the second condition or the false condition you could pass saveNow = true so it becomes

flash.put(name = ‘success’, value = 'There was a problem posting the Advertisement. ', saveNow = true);

That should work for you.