ColdBox-3.8.1/CF10 - RC value lost

ok, I think I need other set of eyes on this code…I’m sure it’s something minor that I’m not seeing…

I have code that displayed an editor form:
function editor(event,rc,prc){
event.paramValue(“id”, " ");
prc.system = ppsdService.get(rc.id);
event.setView(“ppsd/editor”);
}

This code for the form:

#html.startForm(action=“PPSDHandlerORM.save”)#
#html.entityFields(entity=prc.system,fieldwrapper=“div”)#
#html.submitButton()# or #html.href(href=“PPSDHandlerORM”,text=“Cancel”)#
#html.endForm()#

–As you can see, I cfdump the rc.id value, and it’s there; however, as soon as the submit occurs, which calls to the actions “Save”, rc.id is no longer available, which caused a new id and record to be created instead of editing an existing one… Am I missing something that would cause the rc.id to be ignored as soon as the form action is called?

function save(event,rc,prc){

event.paramValue(“id”, “”);

var system = populateModel(ppsdService.get( rc.id ));
var vResults = validateModel(system );

system.setModifiedDate(now());

prc.system = system;
event.setView(“ppsd/debug”);

if( !vResults.hasErrors() ){
ppsdService.save( system );
getPlugin(“MessageBox”).info(“System Saved!”);
setNextEvent(“PPSDHandlerORM/index”);
}
else{
getPlugin(“MessageBox”).error(messageArray=vResults.getAllErrors());
return editor(event,rc,prc);
}
}

Thank you looking over this for me…

I don’t see you submitting the ID in the form. The request collection only lives for the life of the request. The form submit is a second, unrelated request to the server that start with a fresh rc containing only what was in the form or URL scopes. View source and see if html.entityFields() is outputing the ID. If not, you need to add that as a hidden field.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

I originally thought that was the case; however, this code the same as the example code at http://wiki.coldbox.org/wiki/Models/wiki/Models.cfm (toward the end of the page). I even copied all the same code into my learning project, and only change the model/service name… the Contacts example works just fine with the same form submit call… that is where I got all confused.

and the ID is in the url at the time of form submission… “…/id/adbcedfgadfebersa”

I’m not seeing that in the code sample you provided:

#html.startForm(action=“PPSDHandlerORM.save”)#

There’s no query string there at all. Can you give us a URL to a public page where I can see this happening. Or at least copy and paste the HTML created by your form here?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

Interesting, this is the URL I got the example code from:

http://wiki.coldbox.org/wiki/Models/wiki/Models.cfm

The example code is at the end of the page.

This is the URL from my form:
http://mysite.com/PPSDHandlerORM/editor/id/A6595E9E-8D6D-4316-BC9A-E312C51B39CA

So, the id is in the RC, but submitting form, doesn’t persist the id to the event.

Silly question, but do you have a route setup to handle the route ‘/PPSDHandlerORM/Editor/id/:id’?

No, not specifically, but worth a try…

What puzzled me is that I used the example code and it worked just fine. The exact same code, with just different model.

Yeah, it would seem value-pair translation for routes should be enabled by default (eg. it should “just work”).

I would try dumping the rc in your handler before calling Event.paramValue(“id”, “”) to see if it is actually coming in.

Also, I generally do an Event.getValue(“id”, “mycoolvalue”); to see if exists first, and assign it a default value if not.

I’ve tried dumpling out the rc… and event track the Context Request using the Coldbox debug. The id value exists in the editor form and loaded the correct properities for the form, but as soon as Submit is hit, then the id value which shows in the URL is gone… undefined. I need the editing id value, instead of the default “”, because passing the “” will create a whole new record instead of editing an existing one.

Like I said, I didn’t change anything as far as settings or configuration, the same code from ColdBox example, just different model… I may have to manually set the rc.id value and pass it along to the event on submit. But I still don’t understand why the ColdBox example works and not mine.

What Brad has been trying to tell you is that the RC & PRC are request contexts, these only live for as long as the original request is active. If you submit to a client a form, then the session has ended. Once the person resubmits that data that becomes a new request.

If you wish to have these live over to the next request, you will need to look into keeping them alive with Flash. But be careful, in cases like this it is easier to pull all data up from the what has been requested, rather than push all that data around.

Like Brad, said we need to see the code. But at this stage, you issue lies in the fact that once the request ends, so does the life of the RC & PRC.

> as Submit is hit, then the id value which shows in the URL is gone… undefined.

That seems a little impossible :slight_smile: To confirm, you’re saying that you’re loading a URL like so:

yoursite.com/index.cfm/handler/action/arg1/value1

Yet when you dump out the request collection on THAT request, there is no rc.arg1 defined?

I also don’t see how the id is getting in the form’s action anyway. Looking at the code in the HTMLHelper, it looks like it adds a hidden field for the id. Again, can you provide the exact HTML output by the form and/or give us a public URL we can hit to see this in action?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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