Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MVC Controller Layer on Coldfusion

Posted on 2008-10-03
8
Medium Priority
?
145 Views
Last Modified: 2014-10-24
Hi!

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!
0
Comment
Question by:ctorrescasana
8 Comments
 
LVL 12

Expert Comment

by:pigmentarts
ID: 22642411
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...

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/Cold_Fusion_Markup_Language/Q_23600640.html
0
 

Accepted Solution

by:
ctorrescasana earned 0 total points
ID: 22652892
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!
0
 
LVL 1

Expert Comment

by:keijz
ID: 22657720
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.

0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
LVL 11

Expert Comment

by:BrianMM
ID: 22658987
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.
0
 
LVL 12

Expert Comment

by:pigmentarts
ID: 22659330
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

Sessions:
good idea but will get messy i think

PS
dont forget CF has <cfform preservedata="yes"  etc  which preserves data in a form!
0
 
LVL 1

Expert Comment

by:boodyguard
ID: 24369039
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.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question