Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MVC Controller Layer on Coldfusion

Posted on 2008-10-03
8
Medium Priority
?
142 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
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 add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…

715 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