I am using ColdBox with ColdFusion 10. I wanted to pass an argument say id=1000 with the setView(). I couldn't find any example where a param is being passed.
Here is the code:
component {
// Dependency Injection
property name="requestService" inject="RequestService";
function index(event, rc, prc) {
var response = requestService.save(rc);
if(response.Success EQ true) {
event.setView(view="requests/success"); //Want to pass a param(int)
} else {
event.setView("requests/failure");
}
}
}
There are two main ways to pass values from your handler to your view.
The first is to place the values in the Private Request Collection which is made available in handlers as a struct called "prc". The view has the same "prc" struct available to it. This request collection is available to the entire request and all layouts or views that execute for that request.
In your handler
prc.id = 1000;
event.setView( view="requests/success" );
In your view
<cfoutput>#prc.id#</cfoutput>
If you want a more encapsulated approach that only makes the value available to that view specifically, you can use the "args" parameter to the event.setView() and pass a struct of values that will be made available in the view in a struct called "args".
In your handler
event.setView( view="requests/success", args={ id = 1000 } );
In your view
<cfoutput>#args.id#</cfoutput>