Solved

MVC Controller Layer on Coldfusion

Posted on 2008-10-03
8
137 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

770 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