persist value over a http post request.

All,

how would I persist a variable in the flash RAM across a request
coming from a form submission? ie. I have a form that submits to an
action that is checking for a particular key in the request context...
now from the form action I want to persist a value that's already in
the rc. How would I do this without using a hidden form field...? Is
it possible?
what Im doing now is, in my view checking if a value exists in the rc,
and if so, then set a hidden form field. I'd like to do this all
transparent to the user (experienced)...

any thoughts?

Check this thread:
http://groups.google.com/group/coldbox/browse_thread/thread/4b3ad1eea276b65a/caf64189cd7e0965?lnk=gst&q=flash+ram

To persist a request collection variable in your view without using a
hidden form field, I've used the persistVariables() method. The docs
suggest that it's only available in your event handlers, but I've
found you can use it in your views as well. So in your case, you can
put this code at the top of your view:

<cfif event.valueExists("myVariable")>
   <cfset persistVariables("myVariable")>
</cfif>

Tony,

Where is that in the docs? The persistVariables() should be available everywhere, so I might need to update that section. Can you please send it to me

Hi Luis,
Actually, I was referring to the "What's new In 2.5.2" document:

http://ortus.svnrepository.com/coldbox/trac.cgi/wiki/cbWhatsNew2.52

It doesn't explicitly say where the method can be called from, but the
code example given for the persistVariables() method was one that
you'd use in a handler (presumably -- since it's followed by a
setNextRoute call):

<cfset persistVariables('myObject,myArray,myString')>
<!--- Relocate with Confidence --->
<cfset setNextRoute('main/home')>

I'm not really sure where else the persistVariables() method is
mentioned in the docs. But it wasn't absolutely clear to me that I
could use it in a view until I experimented.

-Tony

awesome.

sounds good. I'll give it a shot.

Hi..

I have tried this method myself. but it doesnt seem to be working, am
unsure why

I have this code in the top of my view

<cfset persistVariables("rc.name_art")>

rc.name_art is the artist name variable in the url....

There is a form in the view..which posts to this method in the event
handler

<!---Edit Artist Action--->
  <cffunction name="setArtist" output="false" returntype="void">
    <cfargument name="EVENT" type="any">
    <!---request to reference collection--->
    <cfset var rc = Event.getCollection()>
    <!---Prepare logic--->
    <cfset artist = createObject('component',"myapp.model.mdl_artists")>
    <cfset rc.qrySetArtist = artist.setArtistDataThe
(nameArt=rc.name,oldNameArt=rc.name_art)>

<!---Reroute back to edit artist page--->
    <cfset setNextRoute("artist/rc.name/edit")>

Remove rc. from persistVariables

Hi there...

I am trying to use this method, but it doesnt appear to be working for
me..

I have the following code at the top of my view

<cfset persistVariables("rc.name_Art")>

where rc.name_Art is the name of a variable in the url...

The view contains a form, which passes to the following event handler

  <!---Edit Artist Action--->
  <cffunction name="setArtist" output="false" returntype="void"
access="public">
    <cfargument name="EVENT" type="any">
    <!---request to reference collection--->
    <cfset var rc = Event.getCollection()>
    <!---Prepare logic--->
    <cfset artist = createObject('component',"myapp.model.mdl_artists")>

    <cfset rc.qrySetArtist = artist.setArtistData
(nameArt=rc.name,oldNameArt=rc.name_art)>

    <!---Reroute back to edit artist page--->
    <cfset setNextRoute("artist/rc.name/edit")>
  </cffunction>

When i submit the form to the event handler i recieve the following
error message "Element NAME_ART is undefined in RC"...just wondering
what im doing wrong, thanks

Hi, sorry posted twice by accident, thanks for response..very quick...

I have removed rc from persist variables, but am still getting the
error..Element NAME_ART is undefined in RC.

Do I have to change the code in my event handler maybe?

Thanks

Check this: QuackFuzed [ Ramblings of a Con..ColdFuzed Mind ]: ColdBox: Using 'Persist'

Or the docs...

Thanks..

I have seen this before, but still cant see where I may be going
wrong...will check the coldbox documentation again..

It sounds to me like the variables don’t exist in the event to begin with. Have you dumped it to verify that it/they do indeed exist?

Thanks

I have viewed the link before, but still unsure what i may be doing
wrong...Ill have a look again at the coldbox documentation

Yeah, if I dump this....there is a variable name_art which currently
reads as oasis....the same as it does in the url
http://localhost:8500/mxRestore/index.cfm/artist/Oasis/edit

Thanks

Wondering if anyone else had any ideas?

Thanks

I'm a little unclear as to what you're trying to do and exactly what
the flow is between your handlers and your views. Could you clarify:

1) Where you are originally setting your rc.name_art variable (you
said that it's in the URL, but it also looks like it's coming from a
form post).
2) After it's set, what handler is it being sent to and where it's
being routed from there.
3) Where are you putting you persistVariables() call?
4) From where are you dumping the requestCollection (a handler or
view)?

I'm sure once I'm clear on all this, i'll be able to help you out.

Ok, thanks Tony

1) The rc.name_art variable is in the URL, but what I want to be able
to do is drag the variable from the URL and persist it to the next
event, instead of using a hidden form field.

2) The form is being posted to a function called Set Artist...shown
below....

<!---Edit Artist Action--->
        <cffunction name="setArtist" output="false"
returntype="void">
                <cfargument name="EVENT" type="any">
                <!---request to reference collection--->
                <cfset var rc = Event.getCollection()>
                <!---Prepare logic--->
                <cfset artist = createObject
('component',"myapp.model.mdl_artists")>
                <cfset rc.qrySetArtist = artist.setArtistData
(nameArt=rc.name,oldNameArt=rc.name_art)>
                <!---Reroute back to edit artist page--->
                <cfset setNextRoute("artist/#rc.name#/edit")>

3) The persist variables call I am putting in the view which contains
the form....

    <cfset persistVariables("name_art")>

4)Im not quite sure what you mean here....but my aim is for the
persistVariable(name_art) at the top of my view to drag its value to
the SetArtist method...so I can use it in my cfset

<cfset rc.qrySetArtist = artist.setArtistData
(nameArt=rc.name,oldNameArt=rc.name_art)>

Hope that makes sense,

Many thanks

Sorry, but it's still not clear to me where the name_art variable is
being set in the request collection. You said that it's in the URL,
but from #2 in your post it still looks like rc.name and rc.name_art
are coming from your form (are you doing a form method="get"?).

Anyway, I think I see what's going on here. You're trying to persist
the variable in the wrong place. When you call the setNextRoute()
method in your setArtist() action, you're starting a new request,
which wipes the request collection clean. That's why you're getting
the message that the name_art variable doesn't exist in the rc once
you relocate back to your form.

Try this:

1) remove the peristVariables call in your view (or just comment it
out for now until you test it)
2) change your setNextRoute() call at the end of your setArtist()
function to this: setNextRoute(route="artist/#rc.name#/edit",
persist="name_art")

See if that works.

I think we may be misunderstanding each other....

On my artist pages...for example ulr ="mysite/artist/amy+winehouse"
the artist name has been set up via the routes to represent the
variable name "name_art"

So if in my view "artist.cfm" If place this code #rc.name_art# I will
see amy winehouse

Now I have a form in this view which allows me to add songs for the
artist "in this case amy winehouse"...

The form submits to my handler "setArtist"..

For the setArtist function to work, it needs to know the artist name I
am submitting the song for, to insert it into the correct database

At the moment, the only way I can let the setArtist method know that I
am submitting the song for amy winehouse, is to include a hidden form
field on my form, like so

<!---Hidden Form Field---->
<input name="name_art"
       type="hidden"
       value="#rc.name_art#">

I would like to be able to remove this hidden form field, but somehow
be able to grab my artists name from the url, so I can pass it on to
my "setArtist" method...

I am currently doing a form method ="post" and rc.name and rc.name_art
are currently coming from the form...

Hope that makes sense..

Many thanks