Solved

MVC Controller Layer on Coldfusion

Posted on 2008-10-03
8
135 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. 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 :…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now