Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>My whole answer is for educationnal purposes only and I strongly advise you to use an existing framework rather than reinventing the <a href="http://cfwheels.org/" rel="nofollow noreferrer">Wheels</a>. Have a look at <a href="https://stackoverflow.com/questions/3361951/picking-a-coldfusion-mvc-framework">Picking a ColdFusion MVC Framework</a></strong></p> <p>You can store the value in the <code>session</code> scope. A lot of frameworks does it using a <em>flash memory</em> concept, which is a temporary memory (implemented as a struct) that destroys members when accessed.</p> <p>Have a look at <a href="http://cfwheels.org/docs/1-1/chapter/using-the-flash" rel="nofollow noreferrer">http://cfwheels.org/docs/1-1/chapter/using-the-flash</a> it's quite straight forward to implement an API that does this.</p> <p>Client code could look like (depending on your implementation):</p> <pre><code>&lt;cfset session.flash.set('importantMsg', 'some important msg')&gt; &lt;cflocation ...&gt; </code></pre> <p>Then from the other page:</p> <pre><code>&lt;cfif session.flash.has('importantMsg')&gt; &lt;!--- The following line should also destroy the 'importantMsg' key ---&gt; #session.flash.get('importantMsg')# &lt;/cfif&gt; </code></pre> <p>Here's an implementation example (not that the implementation is not thread-safe):</p> <p>FlashMemory.cfc</p> <pre><code>&lt;cfcomponent&gt; &lt;cffunction name="init" returntype="FlashMemory"&gt; &lt;cfset variables.instance = {flash = {}}&gt; &lt;/cffunction&gt; &lt;cffunction name="set" returntype="void"&gt; &lt;cfargument name="key" type="string" required="true"&gt; &lt;cfargument name="value" type="any" required="true"&gt; &lt;cfset variables.instance.flash[arguments.key] = arguments.value&gt; &lt;/cffunction&gt; &lt;cffunction name="get" returntype="any"&gt; &lt;cfargument name="key" type="string" required="true"&gt; &lt;cfset var v = variables.instance.flash[arguments.key]&gt; &lt;cfset structDelete(variables.instance.flash, arguments.key)&gt; &lt;cfreturn v&gt; &lt;/cffunction&gt; &lt;cffunction name="has" returntype="boolean"&gt; &lt;cfargument name="key" type="string" required="true"&gt; &lt;cfreturn structKeyExists(variables.instance.flash, arguments.key)&gt; &lt;/cffunction&gt; &lt;/cfcomponent&gt; </code></pre> <p>onSessionStart</p> <pre><code>&lt;cfset session.flash = new FlashMemory()&gt; </code></pre> <p>Also please note that in your case, your remote CFC methods shouldn't return anything. You will use the <em>flash memory</em> to pass data around instead. That means when the method has finished it's work you can simply redirect the client.</p> <p><strong>You probably shouldn't use remote CFC methods in this particular case:</strong></p> <p>I have never really used remote CFC methods as stateful web services. The various advantages of remote CFC methods like their ability to spit out data in multiple data-interchange formats (JSON, WDDX...) is lost with your implementation.</p> <p>You could simply do something like:</p> <p>registration.cfm</p> <pre><code>&lt;cfset errors = session.flash.get('registrationErrors')&gt; &lt;cfif arrayLen(errors)&gt; &lt;!--- Display errors ---&gt; &lt;/cfif&gt; &lt;form method="post" action="register.cfm"&gt; ... &lt;/form&gt; </code></pre> <p>register.cfm</p> <pre><code>&lt;cfset registration = new Registration(argumentcollection = form)&gt; &lt;cfset validator = new RegistrationValidator(registration)&gt; &lt;cfif validator.validate()&gt; &lt;cfset application.userService.register(registration)&gt; &lt;!--- You can also redirect to a page that represents the correct state ---&gt; &lt;cflocation url="registered.cfm" addtoken="no"&gt; &lt;cfelse&gt; &lt;!--- Store the errors collection in the flash memory ---&gt; &lt;cfset session.flash.set('registrationErrors', validator.errors())&gt; &lt;!--- Redirect to the page the user came from ---&gt; &lt;cflocation url="#cgi.http_referer#" addtoken="no"&gt; &lt;/cfif&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload