Your Rating: Results: PatheticBadOKGoodOutstanding! 0 rates

ColdFusion has gone through various language enhancements that will provide a better development experience for ColdFusion developers. The core CFML language enhancements in ColdFusion Splendor includes new language constructs, extended tag support, enhanced script functions, and support for new operations.

This document provides an overview on the language enhancements and changes made in ColdFusion Splendor.

Script support for tags

ColdFusion traditionally allowed you to build your applications using simple tags. However, if you are a developer having adequate knowledge of Object-oriented programming, you can now start accessing all the ColdFusion tags in the ColdFusion script block.

Note: The tag attributes will be passed as name-value pairs. The child tag (and the body in general) should be enclosed in curly brackets, as a function block.

For instance,

Note that the attributes of a tag must be enclosed within a parenthesis and also the attributes must be comma-separated.

Consider the following example:

 

You have been used to writing ColdFusion code as mentioned in the above example. To give you more control, invoking tags inside the ColdFusion script block is now supported.

So, now you can write your code in the following manner:

 

The script support is not available for the following tags:

  • <cfscript>
  • <cfoutput> (use writeOutput() instead)
  • <cfdump> (use writeDump() instead)
  • <cfinvoke> (use invoke() instead)
  • <cfinvokeargument>
  • <cfobject> (use createObject instead)

Script support for custom tags

Custom tags can also be used  in <cfscript> blocks just like normal ColdFusion tags. For instance, 

You might create a custom tag, named cf_happybirthday, to generate a birthday message. You could then use that tag in a ColdFusion page, as follows:

You can also invoke the custom tag as follows:

Also, script support for cfimport-based prefix custom tag has been added. Now you can use prefix-based custom tag in script blocks: 


Query tags as ColdFusion functions

Query tag is also available as a ColdFusion function apart from the generic script syntax for the CFQuery tag. This function simplifies the query execution in the CFScript block.

The usage:

 

See the following example:


Note the function:

 

This function lets you pass unnamed parameters to the query. Use '?' (question mark) as the place-holder for the parameters. The values to the parameters should be passed as an array toparams.

For more information on using the unnamed parameters, see this document.

Note that the following points are applicable:

  • If there are any Query parameters, they must be passed as the second argument of the function. It can be either a struct or an array.
  • If you need to provide additional attribute as a Query parameter (like CFSQLType, list, and separator), you can pass these as struct against that column name.
  • The Query and datasource properties will be passes as the third argument.
  • You can write the SQL statement with a positional parameter.

 

JSON serialization

JSON serialization allows you to convert ColdFusion data into a JSON (JavaScript Object Notation) representation of the data. This feature was made available in ColdFusion 8.

ColdFusion Splendor has enhanced the JSON serialization to support the following new features:

  1. Case preservation of struct keys
  2. Data type preservation
  3. Key-value serialization  of CF Query
  4. Custom serializers

Case preservation of struct keys

Currently, the cases for struct keys are not preserved in ColdFusion. The struct keys get converted to upper case automatically.

For instance, consider the following code:

 

In ColdFusion 10 and earlier vesions, the output generated by the above code will be:

For the release after ColdFusion Splendor, the output generated will be:

 

To enable case preservation of struct keys at the application level, modify the application.cfc file by setting:

 

To  enable case preservation of struct keys at the server level, perform the following tasks:

  1. From the ColdFusion Administrator page, click Server Settings > Settings
  2. Click Preserve case for Struct keys for Serialization
     

Data type preservation

The ColdFusion language is typeless and does not evaluate or preserve the type information at the time of code generation. Due to this reason, the datatype of a property is being decided during runtime, which may cause some unexpected behavior. At the time of JSON serialization, ColdFusion attempts at converting a string to a number. If the attempt is successful, then the passed data type is treated as number irrespective of whether you wanted it to be a string or not.

Starting from ColdFusion Splendor, the data type is preserved during the code execution time for Query and CFCs.

SerializeJSON considers datatypes defined in the database for serialization. If the database defines a column as a string, any number inserted into the column will still be treated as a string by SerializeJSON.

For instance,

 

SerializeJSON respects datatypes defined in the database. 

Consider the CFC property type example:

Entity.cfc

 

 

Index.cfm

 

 

OUTPUT: {"Photo":"000"}

In the previous version of ColdFusion, 000 will be automatically coverted to a number at runtime.

Additional format for query serialization

ColdFusion supports 2 different ways to serialize a query object to a JSON string:

  • Using row
  • Using column

See this existing document.

However, these 2 types are not the easiest to use with AJAX applications. ColdFusion Splendor introduces a new way to serialize a query object to a JSON string:

  • Using struct

All the 3 ways, can be defined at the application-level and will be used in serialized JSON functions if the type is not defined explicitly. In application.cfc, define:

Note that "struct" is also available to be accessible through an AJAX argument. Now you can pass struct  in an AJAX URL to serialize a query object as struct.

ColdFusion Splendor now supports serializing the query object to a JSON string that is AJAX-friendly:

 

The current SerializeJSON function has been enhanced to support the 'key-value' format.

 

If you are using the serialzeQueryAs property in application.cfc, you do not need to specify the serialzeQueryByColumns property unless you need to override the functionality.

Custom serializers

In the application.cfc file, you can register your own handler for serializing and deserializing the complex types. If the serializer is not specified, ColdFusion uses the default mechanism for serialization. For more information see Support for pluggable serializer and deserializer.

Member functions for data structure

A lot of enhancements have been made to the core CFML syntax that will aid in developing ColdFusion-based applications elegantly. One of the primary enhancements is the introduction of member functions for data structure and data objects. You can now start coding in a true object oriented style. ColdFusion 10 has support only for headless function. It does not have OOP-based support for its Data Structures (List, Array, Date, Struct, and  String).

With ColdFusion, you can start using member functions.

For instance, consider the following headless function:

 

It can now be written as:

 

where 'arrayObj' is a reference to the CFArray class.

The following characteristics are applicable for member functions:

  • The reference of underlying data structure can either be a ColdFusion class (coldfusion.runtime.Array) or a  Java class (java.util.List) based on the underlying function call.
  • The type of underlying object class on which the method is invoked need not be typed explicitly.
  • You are free to call any ColdFusion APIs on an object that points to the Java interface directly, if the ColdFusion class extends/implements the Java class.

 The following example depicts the new usage of member functions:

 

Member function for the following data types are supported:

  • Array
  • String
  • List
  • Struct
  • Date
  • Spreadsheet
  • XML
  • Query
  • Image                                                             

Supported Array member functions

The following Array member functions are supported:

ArrayAppendsomeVar.append()
ArrayAvgsomeVar.avg()
ArrayClearsomeVar.clear()
ArrayDeleteAtsomeVar.deleteAt()
ArrayInsertAtsomeVar.insertAt()
ArrayContainssomeVar.contains()
ArrayEachsomeVar.each()
ArraySlicesomeVar.slice()
ArrayIsDefinedsomeVar.isDefined()
ArrayIsEmptysomeVar.isEmpty()
ArrayLensomeVar.len()
ArrayMaxsomeVar.max()
ArrayMinsomeVar.min()
ArrayDeletesomeVar.delete()
ArrayFiltersomeVar.filter()
ArrayFindAllNoCasesomeVar.findAllNoCase()
ArrayPrependsomeVar.prepend()
ArrayResizesomeVar.resize()
ArraySetsomeVar.set()
ArraySortsomeVar.sort()
ArrayFindsomeVar.find()
ArrayFindAllsomeVar.findAll()
ArraySumsomeVar.sum()
ArraySwapsomeVar.swap()

 

Supported String member functions

The following String member functions are supported:

InsertsomeVar.insert()
UCasesomeVar.uCase()
LCasesomeVar.lcase()
LeftsomeVar.left()
RightsomeVar.right()
RJustifysomeVar.rjustify()
LJustifysomeVar.Justify()
CJustifysomeVar.cJustify()
MidsomeVar.min()
LensomeVar.len()
TrimsomeVar.trim()
RemoveCharssomeVar.removeChars()
ComparesomeVar.compare()
CompareNoCasesomeVar.compareNocase()
RepeatStringsomeVar.repeatString()
RTrimsomeVar.trim()
ReplaceNoCasesomeVar.replaceNocase()
ReplacesomeVar.replace()
WrapsomeVar.wrap()
SpanExcludingsomeVar.spanExcluding()
SpanIncludingsomeVar.spanIncluding()
ReversesomeVar.reverse()
StripCRsomeVar.stripCR()
FindsomeVar.find()
FindNoCasesomeVar.findNoCase()
FindOneOfsomeVar.findOneOf()
GetTokensomeVar.getToken()

Similarly, the following String member functions are also supported:

Decrypt, Encrypt, BinaryDecode, BinaryEncode, CharsetDecode, CharsetEncode, URLDecode, URLEncodedFormat, HTMLEditFormat, HTMLCodeFormat, ParagraphFormat, JSStringFormat, XmlFormat, FormatBaseN, HTMLEditFormat, HTMLCodeFormat, ParagraphFormat, ToBinary, ToString, ToBase64, Val, GenerateSecretKey, Hash, REFind, REFindNoCase, REMatch, REMatchNoCase, REReplace, REReplaceNoCase, ReplaceList, SpanExcluding, SpanIncluding, LSParseEuroCurrency, LSParseDateTime, LSIsCurrency, LSIsDate, LSIsNumeric, LSParseCurrency, LSParseNumber, and ParseDateTime

Supported List member functions

The following List member functions are supported:

ListAppendsomeVar.append()
ListChangeDelimssomeVar.changeDelims()
ListContainssomeVar.contains()
ListContainsNoCasesomeVar.containsNoCase()
ListDeleteAtsomeVar.deleteAt()
ListFindsomeVar.ListFind ()
ListFindNoCasesomeVar.ListFindNoCase()
ListFirstsomeVar.first()
ListGetAtsomeVar.getAt()
ListInsertAtsomeVar.InsertAt()
ListLastsomeVar.last()
ListLensomeVar.listLen()
ListPrependsomeVar.prepend()
ListQualifysomeVar.qualify
ListRestsomeVar.rest()
ListSetAtsomeVar.setAt()
ListSortsomeVar.sort()
ListToArraysomeVar.toArray()
ListValueCountsomeVar.valueCount()
ListValueCountNoCasesomeVar.valueCountNoCase()
ReplaceListsomeVar.replace()

 

Supported Struct member functions

The following Struct member functions are supported:

StructIsEmptysomeVar.isEmpty()
StructAppendsomeVar.append()
StructClearsomeVar.clear()
StructCopysomeVar.copy()
StructCountsomeVar.count()
StructDeletesomeVar.delete()
StructFindsomeVar.find()
StructFindValuesomeVar.findvalue()
StructUpdatesomeVar.update()
StructSortsomeVar.sort()
StructInsertsomeVar.insert()
StructEachsomeVar.each()
StructKeyArraysomeVar.keyArray()
StructKeyExistssomeVar.KeyExists()
StructKeyListsomeVar.keyList()

 

Supported Date member functions

The following Date member functions are supported:

CreateODBCDatesomeVar.createODBCDate()
CreateODBCDateTimesomeVar.createODBCDateTime()
DateDiffsomeVar.diff()
CreateODBCTimesomeVar.createODBCTime()
LSDateFormatsomeVar.LSDateFormat()
DatePartsomeVar.datepart()
DaysInYearsomeVar.daysIn
SecondsomeVar.second()
MinutesomeVar.minute()
HoursomeVar.hour()
DaysomeVar.Day()
WeeksomeVar.week()
MonthsomeVar.month()
QuartersomeVar.quarter()
YearsomeVar.year()
DaysInMonthsomeVar.DaysInMonth()
DayOfWeeksomeVar.DayOfweek()
DayOfYearsomeVar.dayOfYear()
FirstDayOfMonthsomeVar.firstDayOfMonth()
DateTimeFormatsomeVar.DateTimeFormat()
TimeFormatsomeVar.TimeFormat()
DateFormatsomeVar.DateFormat()
DateAddsomeVar.add()
DateConvertsomeVar.convert()

Supported Image member functions

The following Image member functions are supported:

ImageGetWidthsomeVar.getWidth()
ImageSetDrawingColorsomeVar.setDrawingColor()
ImageGetBufferedImagesomeVar.getBufferedImage()
ImageTranslateDrawingAxissomeVar.translateDrawingAxis()
ImageSetDrawingStrokesomeVar.setDrawingStroke()
ImageNegativesomeVar.negative()
ImageCopysomeVar.copy()
ImageDrawRectsomeVar.drawRect()
ImageCropsomeVar.crop()
ImageGetHeightsomeVar.getHeight()
ImageGetIPTCTagsomeVar.getIPTCTag()
ImageDrawOvalsomeVar.drawOval()
ImageSharpensomeVar.sharpen()
ImageOverlaysomeVar.overlay()
ImageGetEXIFTagsomeVar.getEXIFTag()
ImageDrawBeveledRectsomeVar.drawBeveledRect()
ImageAddBordersomeVar.addBorder()
ImageShearsomeVar.shear()
ImageInfosomeVar.info()
ImagePastesomeVar.paste()
ImageDrawArcsomeVar.drawArc()
ImageShearDrawingAxissomeVar.shearDrawingAxis()
ImageDrawRoundRectsomeVar.drawRoundRect()  
ImageGrayscalesomeVar.grayscale()
ImageSetDrawingTransparencysomeVar.setDrawingTransparency()
ImageScaleToFitsomeVar.scaleToFit()
ImageClearRectsomeVar.clearRect()
ImageTranslatesomeVar.translate()
ImageFlipsomeVar.flip()
ImageWriteBase64someVar.writeBase64()
ImageSetBackgroundColorsomeVar.setBackgroundColor()
ImageDrawLinesomeVar.drawLine()
ImageDrawQuadraticCurvesomeVar.drawQuadraticCurve()
ImageRotatesomeVar.rotate()
ImageGetBlobsomeVar.getBlob()
ImageWritesomeVar.write()
ImageBlursomeVar.blur()
ImageRotateDrawingAxissomeVar.rotateDrawingAxis()
ImageSetAntialiasingsomeVar.setAntialiasing()
ImageDrawPointsomeVar.drawPoint()
ImageDrawCubicCurvesomeVar.drawCubicCurve()
ImageXORDrawingModesomeVar.xorDrawingMode()
ImageDrawTextsomeVar.drawText()
ImageDrawLinessomeVar.drawLines()
ImageResizesomeVar.resize()

Supported Spreadsheet member functions

The following Spreadsheet member functions are supported:

SpreadsheetDeleteRowsomeVar.deleteRow()
SpreadsheetFormatColumnsomeVar.formatColumn()
SpreadsheetShiftRowssomeVar.shiftRows()
SpreadsheetCreateSheetsomeVar.createSheet()
SpreadsheetReadBinarysomeVar.readBinary()
SpreadsheetWritesomeVar.write()
SpreadsheetAddRowsomeVar.addRow()
SpreadsheetShiftColumnssomeVar.shiftColumns()
SpreadsheetGetCellFormulasomeVar.getCellFormula()
SpreadsheetDeleteColumnssomeVar.deleteColumns()
SpreadsheetAddFreezePanesomeVar.addFreezePane()
SpreadsheetDeleteColumnsomeVar.deleteColumn()
SpreadsheetSetCellCommentsomeVar.setCellComment()
SpreadsheetSetActiveSheetNumbersomeVar.setActiveSheetNumber()
SpreadsheetSetHeadersomeVar.setHeader()
SpreadsheetAddSplitPanesomeVar.addSplitPane()
SpreadsheetMergeCellssomeVar.mergeCells()
SpreadsheetFormatRowssomeVar.formatRows()
SpreadsheetGetCellComment getCellComment()
SpreadsheetGetCellValuesomeVar.getCellValue()
SpreadsheetAddInfosomeVar.addInfo()
SpreadsheetSetCellValuesomeVar.setCellValue()
SpreadsheetSetFootersomeVar.setFooter()
SpreadsheetRemoveSheetsomeVar.removeSheet()
SpreadsheetSetRowHeightsomeVar.setRowHeight()
SpreadsheetSetActiveSheetsomeVar.setActiveSheet()
SpreadsheetFormatCellRangesomeVar.formatcellRange()
SpreadsheetFormatCellsomeVar.formatCell()
SpreadsheetAddRowssomeVar.addRows()
SpreadsheetFormatColumnssomeVar.formatColumns()
SpreadsheetAddImagesomeVar.addImage()
SpreadsheetSetCellFormulasomeVar.setCellFormula()
SpreadsheetAddColumnsomeVar.addColumn()
SpreadsheetDeleteRowssomeVar.deleteRows()
SpreadsheetSetColumnWidthsomeVar.setColumnWidth()
SpreadsheetFormatRowsomeVar.formatRow()
SpreadsheetInfosomeVar.info()

Supported XML member functions

The following XML member functions are supported:

XmlTransformsomeVar.transform()
XmlGetNodeTypesomeVar.getNodeType()
XmlChildPossomeVar.childPos()
XmlElemNewsomeVar.elemNew()
XmlSearchsomeVar.search()

Supported Query member functions

The following Query member functions are supported:

QueryAddColumnsomeVar.addColumn()
QueryGetRowsomeVar.getRow()
QueryConvertForGridsomeVar.convertForGrid()
QuerySetCellsomeVar.setCell()
QueryAddRowsomeVar.addRow()
 someVar.getResult()

Support for Elvis operator (?:)

The support has been provided in ColdFusion for the Elvis operator (?:). The Elvis operator is primarily used to assign the ‘right default’ for a variable or an expression. In an expression, if the resultant value is not defined, then the object will be assigned to the left most part of the expression otherwise a default value (define at the right most part) will be assigned.


For instance,

 

In the above example, if userName is defined, it will be assigned to the myDisplayName variable. If the userName is not defined, the value “Anonymous” will be assigned to the myDisplayName variable.

See the following example:

 

In the above example, if getEmployeeName(ID) does not return any value, the value “Joe” will be assigned to the employeeName variable.

Similiarly, you can use this operator for Struct:

 

Passing array index to callback functions in ArrayEach

Currently, ColdFusion supports passing objects in callback function. Now, from ColdFusion Splendor,  you can pass the index of an array to the callback function as shown below:

 

Support for ListEach (New)

Currently, ColdFusion supports passing objects in callback function. Now, from ColdFusion Splendor,  you can pass the index of an array to the callback function as shown below:

  

Support for QueryGetRow (New)

 

A new function, QueryGetRow, has been introduced. This function returns a struct having all the columns as keys and their corresponding values:


Preference for built-in functions

The ColdFusion built-in functions will be treated as ‘first-class’ functions so that any built-in function can be passed as an argument.

For instance,

This is valid:

Now, you can treat the built-in CFML functions  like ucase() as objects, being able to assign them to variables, and pass them as arguments.

Support for database queries (Beta)

You can start using the <cfquery> tag in client-side CFML just like how you are currently using it in server-side CFML code. Note that not all of the <cfquery> features are supported in this release.

See Mobile Application Development

 

Added script support for cfimport based prefix custom tag. Now you can use prefix based custom tag in script block without any issue.

test.cfm
<cfscript>
  cfimport(taglib=" ../importFolder/" prefix="myTags");
  myTags:customTag();
</cfscript>

customTag.cfm
<cfoutput > Output from custom tag </cfoutput>

Labels
  • None
  1. Apr 09, 2014

    The first class function example does not work at all.

    1. Apr 09, 2014

      Ray,

      I've changed the example.


Searching ColdFusion English Documentation