To illustrate an "errorBean" a little further (since I received a few
requests as to how this can be accomplished) I'll include an example
below...
<cfcomponent name="ErrorBean" output="false">
<!--- create an errors structure --->
<cfset variables.errors = StructNew() />
<cffunction name="addError" access="public" output="false"
returntype="void" hint="Adds a new error to the error structure">
<cfargument name="name" required="true" type="string" hint="Name
of the error; best practice to use form name here" />
<cfargument name="message" required="true" type="string"
hint="Message regarding this error" />
<cfset variables.errors[
arguments.name] = arguments.message />
</cffunction>
<cffunction name="getError" access="public" output="false"
returntype="string" hint="Returns an error from the error structure">
<cfargument name="name" required="true" type="string" hint="Name
of the error to return; if error doesn't exist, returns empty string" /
>
<cfif hasError(
arguments.name)>
<cfreturn variables.errors[
arguments.name] />
<cfelse>
<cfreturn '' />
</cfif>
</cffunction>
<cffunction name="hasError" access="public" output="false"
returntype="boolean" hint="Returns true if the error exists within the
error structure">
<cfargument name="name" required="true" type="string" hint="Name
of the error to check" />
<cfreturn StructKeyExists(variables.errors,
arguments.name) />
</cffunction>
<cffunction name="hasErrors" access="public" output="false"
returntype="boolean" hint="Returns true if there is at least one
error">
<cfreturn NOT StructIsEmpty(variables.errors) />
</cffunction>
</cfcomponent>
My recommendation is to instantiate the ErrorBean in the plugin, then
when your filters run, your ErrorBean will exist within the Event
scope. When you're doing form-field validation, as an example, you
can put any errors you find within the ErrorBean so that you can
report the issues back to the users in a contextual fashion.
In your filter whilst doing validation:
<cfset var errorBean = arguments.event.getArg('errorBean') />
<cfif NOT Len(arguments.event.getArg('firstName')>
<cfset errorBean.addError('firstName', 'You must provide a first
name!') />
</cfif>
Then at the end of your filter you can:
<cfif errorBean.hasErrors()>
<cfset announceEvent('TheEventIOriginallyCameFrom') />
<cfreturn false />
</cfif>
And to display the error message next to the input field it originated
from, in your view you can:
<cfset errorBean = request.event.getArg('errorBean') />
...
<cfif errorBean.hasError('firstName')>
<div class="error">#errorBean.getError('firstName')#</div>
</cfif>
<input type="text" name="firstName" value="#request.event.getArg
('firstName')#" />
This is, of course, one of many possible ways to utilize filters and
plugins to report issues back to the user as well as change the flow
of the event. If you have any questions, feel free to respond to this
thread so that all can see them!
Adrian.