frameworks

Previously in How to use jQuery UI Autocomplete with ColdBox and Bootstrap the value used was singular and also the record identifier. However what if we want to submit the identifier but show another text value for the auto-suggest to the user, for example, if we want to show the client’s full name for auto suggest, but submit the client’s ID.

The environment used for this example is:

ColdBox 3.8

BootStrap 3.1.1

ColdFusion 10

The steps are essentially the same (the differences are in the helper function and front end UI), i.e.

Reference jQuery UI in the main layout

Create a helper function to retrieve the required data

Use autocomplete on the view page

1 Reference the jQuery UI in the main layout

Open layouts\Main.cfm and add the following reference to the style sheet and JavaScript for jQuery UI (if not already present), i.e.

Lastly, don’t forget to link to the style sheet (including the application’s styles) and scripts for FormValidation JS and jQuery in the appropriate places (in the head section for styles, and body for scripts):

Like this:

In a previous blog post on using the ColdBox MailService we made use of the service’s SetBodyTokens method to pass through simple values, that is something like this:

/* define the token for use in the email view.
this is the dynamic content for the html email body */
email.setBodyTokens({
title = emailTitle,
firstName = arguments.user.getFirstName(),
url = baseURL & "/reports/list"
});

Then in the view used to display the email body content, any placeholder variables will be replaced with the passed in value. That is @title@ will be replace with the value passed in. So if a value of Cool Programmer was passed in, then @title@ will now show Cool Programmer.

Using the SetBodyTokens method means that we can not passed in complex values like an array or a struct. To overcome this issue we will instead use the MailService’s SetBody method to pass in the value via the argsparameter to the email body’s viewtemplate.

Firstly, in the handler where the MailService is invoke and where the sendUserDetailsfunction is defined, add the following dependency injections at the top of the file:

In the view for the email body (i.e. view=”userDetails”), the passed in values are in the args scope, so to access them we refer to each variables as args.variable-name (i.e. replace stInfowith args: args.firstname). Here’s a partial code snippet to illustrate:

We use the injected configBeanto retrieve settings from the ConfigurationCFC(coldbox.cfc) and set the base URL

Then we create a new mail message using MailService’s newMailmethod

Then we define the token for the body and add the html email. The content of the html email is defined in the views folder. In the above example, a view template called newEntry.cfm should be created and saved under the views/notifications sub-folder

Finally we send it using the MailService plugin’s sendmethod.

Create the email view

Under the viewsfolder, create a subfolder called notifications. Then in this new subfolder create a new file called newEntry.cfm and add the following code snippet:

And let’s say you are querying the Reportentity but also want to show Confirmation, Staffand Team entity details in a ColdBox view. How would you do use ORM associations and ColdBox’s CriteriaBuilderto navigate multiple associations and bring back the required information?

Here’s how we can achieve that goal by using the ColdBox CriteriaBuilder’s CreateAlias method:

Create a link from Reportto Confirmationwith CreateAlias

Create a second link from Confirmationto Staffwith CreateAlias

Lastly, create a third link from Staffto Teamwith CreateAlias

Link all of the above together by chaining the CreateAlias, i.e. CreateAlias().CreateAlias().CreateAlias()

In your Report entity handler Report.cfc, maybe you have an action that retrieve the information for the Report entity listing view. Let’s say this action is called list. Here’s the code to retrieve the information from the Report, Confirmation, User and Team entities:

We are chaining the CreateAliasmethod to link the entities via their associations, so we can traverse the entities and display the required information.

3. Displaying the Information

Ok, we should now be able to retrieve all the information we needed using ColdBox CriteriaBuilder. Let’s see how we can access and display them. And let’s say we want to display the following information:

Like this:

Ever wanted to easily export tabular data as csv, pdf, Excel in addition to copying and printing them with just a click in a ColdBox or any web applications and sites? Well, you can by using jQueryand DataTables, and it is as easy as 1-2-3:

Link to the libraries

Initialise the table and buttons

Test the buttons

Link to the Libraries

In the html page head add the following styles for the DataTables table and buttons: