Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Adobe ColdFusion 9
Search
Product support
View Help PDF ( 23MB)
Home / Developing ColdFusion 9 A pplications / Requesting and Presenting Information / Using A jax Data and Development Features
Tags
Supported formats
autosuggest
cfinput type="text"
1, 2, 3
bind
1, 2, 3, 5
bind
1, 2, 3
onChange
cfgrid
1, 2, 3
source
bind="cfc:myapp.bookorder.getChoices({book})"
source="/myApp/innerSource/cityWindow.cfm?cityname={inputForm:city}
In these examples, {book}and {inputForm:city}specify bind parameters that dynamically get data from the book and city controls, and the city control is in the inputForm form.
If a bind attribute specifies a page that defines JavaScript functions, the function definitions on that page must have the following format:
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7a0a.html
1/6
8/7/2014
Function definitions that use the following format may not work:
However, Adobe recommends that you include all custom JavaScript in external JavaScript files and import them on the applications main page, and not write them inline in code that
you get using the source attribute. Imported pages do not have this function definition format restriction.
bind="cfc:myapplication.bookSearch.getStores({form1:bookTitle})"
In this example, the bind parameter is form1:bookTitle and specifies the valueattribute of the bookTitle field of the form1form.
Bind parameters have either of the following formats:
{[formName:]controlName[.attributeName][@event]}
{SpryDataSetName.fieldName}
The brackets ([]) indicate optional contents and are not part of the parameter.
Note: To include a literal brace character in a bind expression, escape the character with a backslash, as \{, \}.
The formname value
The formname entry identifies the form that contains the control you are binding to. Specify a form name if multiple forms contain bind targets with the same names. To specify the
form name, start the bind expression with the forms idattribute the nameattribute if you did not specify an idattribute, and follow it with a colon (:). To specify the bookcontrol that
is in a form named inputForm, for example, use the following format:
bind="cfc:myapp.bookorder.getChoices({inputForm:book})"
bind="cfc:myapp.bookorder.useStatus({myForm:approved.checked@click})
Note: You can bind to the display text of a select box, instead of the value, by specifying an attribute name of innerHTML.
Note: When you bind to a check box, use the @clickevent specifier to ensure that the bind expression is triggered in Internet Explorer when the user selects or deselects the check
box, not when the box loses focus.
Grids and trees do not have default bind attributes.
Always specify a grid target attribute by using the format {gridID.columnName}. The bind expression gets the value of the specified column in the selected row.
For trees, you must bind to a specific node in the tree. Specify the node by using the node ID or an explicit path to the node.
To bind to a Spry data set element or attribute, use standard Spry path notation. For example, specify an element name.
The event value
By default, the bind expression function executes each time the control specified in the bind parameter has an onChangeevent. To trigger updates on a different JavaScript event, end
the bind expression with an at sign (@) and the event name, without the on prefix. The following code, for example, executes the getC hoices C FC each time the user presses the
mouse button while the pointer is over the bookcontrol:
bind="cfc:myapp.bookorder.getChoices({inputForm:book@mousedown})"
Note: To bind to a cfinputcontrol with typeattribute of button, specify a bind event setting, such as click. The changeevent is the default event has no effect.
When you bind to a Spry data set, do not specify an event. The expression is evaluated when the selected row changes in the data set, or when the data set reloads with new data.
You can also specify that a specific bind parameter never triggers bind expression reevaluation, by specifying @noneas the event. This is useful, for example, if a bind expression
uses multiple bind parameters binding to different form fields, and you want the bind expression to trigger changes only when one of the fields changes, not when the others change.
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7a0a.html
2/6
8/7/2014
In this case, you would specify @nonefor the remaining fields, so events from those fields would not trigger the bind. The following code shows this use:
bind="cfc:books.getinfo({iForm:book}, {iForm:author@none})"
The @noneevent specifier is also useful when used with autosuggest text inputs, trees and grids, as follows:
When you use an autosuggest text input, the bind expression is evaluated as a user types in text, and picks up data from all bind parameters, including those parameters with
@nonespecified. Therefore, for autosuggest, specify @nonefor all bind parameters, because there is no way for it to react to changes in the parameters.
When you call the ColdFusion.Grid.refreshor ColdFusion.Tree.refreshfunction, the function fetches data from all bind parameters when it evaluates the bind
expression, including any parameters with @nonespecified. If you specify @nonefor all bind parameters, the tree or grid might not respond to changes in other controls, but
gets data from all the bind parameters each time you explicitly refresh it.
bind="cfc:mycfc.myfunction(arg1={myform:myfield1},arg2={myform:myfield2})"
Usage
The following code shows the usage of this enhancement using per-map mappings:
Application.cfc
THIS.mappings["/mycfc"] = "C:\www\shared\components";
Test.cfm
<cfajaxproxy cfc="mycfc.utils" jsclassname='jsobjname' />
Example
In this example, a per-app mapping named mycfcshas been created in Application.cfc pointing to "c:\components". For the sample code to work, create a folder named components
in your system root (in this example, c:\) and copy the Employee.cfc to that folder.
Application.cfc
<cfcomponent>
<cfset this.name = "cfcoutsidewebroot">
<cfset this.sessionmanagement = true>
<Cfset mappingname = "/mycfcs">
<Cfset mappingpath = "c:\components\">
<cfset this.mappings[mappingname] = mappingpath>
</cfcomponent>
Employee.cfc
<cfcomponent>
<cfscript>
remote any function getEmployees(page,pageSize,gridsortcolumn="EMP_ID",gridsortdirection="ASC"){
var startRow = (page-1)*pageSize;
var endRow = page*pageSize;
if(!isdefined("arguments.gridsortcolumn") or isdefined("arguments.gridsortcolumn") and trim(arguments.gridsortcolumn) eq "")
gridsortcolumn = "EMP_ID";
if(!isdefined("arguments.gridsortdirection") or isdefined("arguments.gridsortdirection") and arguments.gridsortdirection eq "")
gridsortdirection = "ASC";
var mysql = "SELECT Emp_ID, FirstName, EMail, Department FROM Employees";
if(isdefined("arguments.gridsortcolumn") and arguments.gridsortcolumn neq "")
mysql = mysql & " ORDER BY " & gridsortcolumn;
if(isdefined("arguments.gridsortdirection") and arguments.gridsortdirection neq "")
mysql = mysql & " " & gridsortdirection ;
rs1 = new query(name="team", datasource="cfdocexamples", sql=mysql).execute();
return QueryConvertForGrid(rs1.getResult(), page, pageSize);
}
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7a0a.html
3/6
8/7/2014
Employee.cfm
<cfform>
<cfgrid
format="html"
name="grid01"
pagesize=10
title="Employee database"
bind="cfc:mycfcs.employee.getEmployees({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})"
onChange="cfc:mycfcs. employee.editEmployees({cfgridaction},{cfgridrow},{cfgridchanged})">
<cfgridcolumn name="Emp_ID" display=false header="ID" />
<cfgridcolumn name="FirstName" display=true header="First Name"/>
<cfgridcolumn name="Email" display=true header="Email"/>
<cfgridcolumn name="Department" display=true header="Department" />
</cfgrid>
</cfform>
<html>
<head>
</head>
<body>
<cfform name="mycfform">
First Name: <cfinput type="text" name="firstname" value=""><br>
Last Name: <cfinput type="text" name="lastname" value=""><br>
Domain: <cfinput type="text" name="domain" value=""><br>
E-mail: <cfinput type="text" name="email1" size="30"
bind="{firstname}.{lastname}@{domain}">
</cfform>
</body>
</html>
The following example shows the results of binding to radio buttons and check boxes with the same nameattribute but different idattributes. Notice that because each control has a
separate idvalue that is used in the labeltags, you click the labels to select and deselect the controls.
<html>
<head>
</head>
<body>
<cfform name="myform">
Pick one:
<cfinput id="pickers1" name="pickone" type="radio" value="Apples">
<label for="pickers1">Apples</label>
<cfinput id="pickers2" name="pickone" type="radio" value="Oranges">
<label for="pickers2">Oranges</label>
<cfinput id="pickers3" name="pickone" type="radio" value="Mangoes">
<label for="pickers3">Mangoes</label>
<br>
<cfinput name="pickone-selected" bind="{pickone}"><br />
<br />
Pick as many as you like:
<cfinput id="pickers4" name="pickmany" type="checkbox" value="Apples">
<label for="pickers4">Apples</label>
<cfinput id="pickers5" name="pickmany" type="checkbox" value="Oranges">
<label for="pickers5">Oranges</label>
<cfinput id="pickers6" name="pickmany" type="checkbox" value="Mangoes">
<label for="pickers6">Mangoes</label>
<br/>
<cfinput name="pickmany-selected" bind="{pickmany}"><br />
</cfform>
</body>
</html>
Most applications call a C FC function, or JavaScript function, or use a URL to make an HTTP request (typically to a C FML page), and pass bind parameters as the function or URL
parameters.
The following example uses the same form as the first example in the preceding section, but uses a different bind expression with the following features:
It uses the keyupevents of the name and domain fields to trigger binding. So the e-mail field gets updated each time that you enter a letter in any of these fields.
It calls a C FC , which uses only the first letter of the first name when forming the e-mail address, and forces the domain name to be all lowercase.
The following example shows the bindapp.cfm page:
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7a0a.html
4/6
8/7/2014
<cfcomponent>
<cffunction name="getEmailId" access="remote">
<cfargument name="firstname">
<cfargument name="lastname">
<cfargument name="domain">
<cfreturn "#left(arguments.firstname,1)#.#arguments.lastname#@#lcase(arguments.domain)#">
</cffunction>
</cfcomponent>
Many of the examples in the documentation for C oldFusion Ajax features use binding, including more complex forms of binding.
<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 bindattribute in a cfajaxproxytag. For the sake of brevity, the bind expression calls a JavaScript function; as a result,
the cfajaxproxytag cannot use a onErrorattribute.
<html>
<head>
<script language="javascript">
function test(x,y){
return "Hello, " + x + "!";
}
function callbackHandler(result){
alert("Bind expression evaluated. Result: \n" + result);
}
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7a0a.html
5/6
8/7/2014
Twitter and Facebook posts are not covered under the terms of C reative C ommons.
Home / Developing ColdFusion 9 A pplications / Requesting and Presenting Information / Using A jax Data and Development Features
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7a0a.html
6/6