
868
DEVELOPING
COLDFUSION 9 APPLICATIONS
Requesting and Presenting Information
Las
t
upda
te
d 8/5/2010
•
The
onSuccess
function handles a valid return from the function or page and updates the display as required with
the returned information.
Binding a function or request by using the
cfajaxproxy
tag enables you to perform a server-side action, such as
updating a database by using bind parameter values based on a user action in some control, and then run a specific
action or set of actions in one or more controls based on the server response. Because it uses an
onSuccess
function
to process the return from the server, this form of binding provides substantially more flexibility than a CFML control
bind
parameter. This format also lets you use a control
bind
parameter for one kind of action, and the
cfajaxproxy
tag for a different activity.
For example, if you have a form with an editable
cfgrid
control and a delete button that a user clicks to delete a grid
row. The application must have the following behaviors:
•
When the user clicks the delete button two things must happen:
•
The application must call a mycfc.deleteButton CFC function to delete the row from the database.
•
The grid must update to remove the deleted row.
•
When the user edits the grid content, the grid must call a
mycfc.update
function to update the database.
Implement these behaviors by doing the following:
•
In the
cfgrid
tag, specify a
bind
attribute that uses a bind expression to call a mycfc.update function each time the
user changes the grid contents.
•
In a
cfajaxproxy
tag, specify a
bind
attribute that calls the mycfc.deleterow CFC function, and specify an
onSuccess
attribute that calls the
ColdFusion.Grid.refresh
function to update the displayed grid when the
CFC function returns successfully.
The following code snippets show how you could do this:
<cfajaxproxybind="cfc:mycfc.deleteRow({deletebutton@click},
{mygrid.id@none}"onSuccess="ColdFusion.Grid.refresh('mygrid', true)">
...
<cfinput type="button" name="deletebutton">
<cfgrid name="mygrid" bind="mycfc.update({cfgridpage}, {cfgridpagesize},
{cfgridsortcolumn}, {cfgridsortdirection})>
The following complete example shows a simple use of the
bind
attribute in a
cfajaxproxy
tag. For the sake of brevity,
the bind expression calls a JavaScript function; as a result, the
cfajaxproxy
tag cannot use a
onError
attribute.