• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 146
  • Last Modified:

MVC Controller Layer on Coldfusion


I´m trying to build a application on ColdFusion based on MVC, but not using a Framework.

I´ve built some pagelets with forms that submit the content to a controller with an action like "/controllers/Publication.cfc" with the method as input argument. At controller i have some methods to validate the input and if it is all ok, update the database and finaly call another view.

My question is: when the validation is not ok, i want to send the user to the first view again and mantain the form with the information the user gave and also send him the validation error result.

I could not find a way to handle a callback. Is there some way to do this?
I´d like not to use session variables

And sorry if my question is a bit stupid! I'm new at MVC in Coldfusion.

Tks for your attention!
1 Solution
without sessions the only way I can think of would be with to have your validation an AJAX, or callback of some sort.

this way your page makes the call waits for the response and either updates the view or shows validation errors

something like so...

ctorrescasanaAuthor Commented:
Hi pigmentarts! Hi all!

Using session, is there some way?

I´d like to submit the form to the controller, validate and: IF OK, update, IF NOT go back to the form and output an error message asking the user to verify what is wrong and resubmit. I saw a way to do this with Java, but I´m not seeing how to do this with ColdFusion.

I´ve read some material of MVC in ColdFusion but I couldnt find any hat explains how to do this. They just show solutions when the validation results OK.

An event handler would help me?

Tks for any help!
There are ways of doing this.
The problem here lies with persisting the submitted form across page requests.
Using the session is usefull, because it persists among requests.

Another way to do this, is to access your view without doing a new page request.
You could use a wrapper method in publication.cfc that either includes your view or "renders" your view using cfsavecontent with cfinclude, then outputs that to the browser. Your old view could be accessed by using a hidden input.

Using client-side validation (javascript) instead of server-side validation (coldfusion) would also defeat this problem. When the form is submitted you already know that the input is valid. If you do NEED server-side validation ie. to check if a username is taken or not, then AJAX is also a solution.

When you use a framework, the upside is that they've already found solutions for problems like this, wich gives you an advantage. Thats the great thing about frameworks.

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

I have recently implemented a 'framework' as I found existing frameworks too constricting in how to implement complex functions...

Anyway... my way around it was to have the notion of 'context' within the website, by using session variables to work out where you are in the site and remember where you were so that you can easily jump from one context to another.
I second the keijz comment on Frameworks. In term of being constricting i dont find this with http://www.cfwheels.com/ or fusebox I find it helps me in the long run to write better code thats reusable. however in smaller project i do find frameworks overkill

Client side
using client-side validation via JavaScript means you dont what to submit the page until it validated. however this gives issues with user who dont use JavaScript

good idea but will get messy i think

dont forget CF has <cfform preservedata="yes"  etc  which preserves data in a form!
Hi all,

The easiest way for me is to use the same cfc and divide the action by case.
First case display
Second validation (test if existing submit, or existing field)

So you have all information in the same page and you can display the wrong input and all previous information that the user type.

This way is faster then using session just for a form.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now