musings

February 28, 2008

CFEclipse on Windows

Filed under: ColdFusion — aliaspooryorik @ 1:29 pm

If you want to get CFEclipse up and runing on Windows then this what you need to do:

Installing Eclipse IDE

  1. Go to http://www.eclipse.org/downloads/
  2. Download Eclipse IDE for Java Developers (windows version)
  3. Extract the zip file to your Program File directory (you don’t install eclipse from an exe or msi file)
  4. Open the directory you extracted your files to
  5. Right click on the eclipse.exe file, hold and drag to your start menu to create a shortcut

Installing CFEclipse

  1. Run eclipse
  2. Accept the default Workspace (you can change it later)
  3. From the help menu, select Software Updates -> Find and Install
  4. Select the “Search for new features” radio button. Next.
  5. Click the “New Remote Site” button
  6. Enter CFEclipse as the name
  7. Enter http://www.cfeclipse.org/update for the URL. OK.
  8. Click the Finish Button
  9. Eclipse will now go off and check the CFEclipse site
  10. Tick all plugin boxes
  11. The next steps are self explainatory…
  12. …Restart Eclipse

Changing the font size and / or colours

  1. Windows menu -> preferences
  2. Expand General -> Appearance -> Colors and Fonts
  3. Expand the Basic folder in the dialog box
  4. Click on Text Font
  5. Click the Change button
  6. Choose your font

View line numbers

  1. Windows menu -> preferences
  2. Expand General -> Editors
  3. Tick the Show Line Numbers box

If you’re new to Eclipse then you should know that you can’t just open a file, first you need to create a new project.

  1. File -> New Project
  2. open the CFEclipse folder and select CFML Project. Next
  3. Enter your project name
  4. Untick the “use default option” box
  5. Browse to your project folder. Finish.

Fusebox 5.5 and SES URLs

Filed under: ColdFusion, Fusebox — aliaspooryorik @ 11:18 am

I’ve been using Fusebox 5.5 since it was released but have been a bit slow to check out the SES handling (I have been using my own URL parsing in Application.cfm and an ASAPI plugin). This didn’t work with the XML-free version on Fusebox 5.5. After much head scratching I worked out why.

First this is what the official Fusebox 5.5 release notes say:

Fusebox 5.1 did not process these URLs coming into the framework so you needed to add your own home-brewed SES URL parser. Fusebox 5.5 will attempt to parse SES URLs coming into the framework if the queryStringStart parameter is set to something other than the default “?”) in fusebox.xml or FUSEBOX_PARAMETERS.

All you need to do is add these lines into the pseudo constructor of your Application.cfc and job done!

// search engine safe parameters...
FUSEBOX_PARAMETERS.queryStringStart ="/"; // default: ?
FUSEBOX_PARAMETERS.queryStringSeparator ="/"; // default: &
FUSEBOX_PARAMETERS.queryStringEqual = "/"; // default: =

Don’t forget to reinitialise the application to make it work!

In my case I also had to use a different script name to the usual index.cfm to stop Fusebox’s URL handling conflicting with my server wide ASAPI plugin URL handling.

February 27, 2008

Sorting table rows with jQuery and ColdFusion

Filed under: ColdFusion, jQuery — aliaspooryorik @ 10:08 pm

I posted a drag and drop example of sorting and saving a list using the jQuery sortables plugin. I was asked how this could be done with table rows. The jQuery TableDnD plugin comes to the rescue!

It doesn’t have serialize method so you need to get the new order yourself which can be done easily by looping through the rows and building a list in the correct order.

<html>
<head>
<script type="text/javascript" src="js/jquery-1.2.3.min.js"></script>
<script type="text/javascript" src="js/jquery.tablednd.js"></script>
<script type="text/javascript">
<!-- <![CDATA[
$(function(){
  $("#sortable-tbl").tableDnD();

  $('#frm-sort').submit(function(){
    var sRowOrder = "";
    $("#sortable-tbl tr").each(function(i,o){
    if (sRowOrder.length) {
      sRowOrder += "," + o.id;
    } else {
      sRowOrder = o.id;
    }
    });
    $('#sort_order').val(sRowOrder);
  });
});
// ]]> –>
</script>
</head>
<body>

<table id=”sortable-tbl”>
    <tr id=”section_id_1″>
    <td>One</td>
    <td>Row A</td>
  </tr>
  <tr id=”section_id_2″>
    <td>Two</td>
    <td>Row B</td>
  </tr>
  <tr id=”section_id_3″>
    <td>Three</td>
    <td>Row C</td>
  </tr>
  <tr id=”section_id_4″>
    <td>Four</td>
    <td>Row D</td>
  </tr>
</table>

<form id=”frm-sort”>
  <input type=”submit” name=”save” id=”save” value=”save” />
  <input type=”hidden” name=”sort_order” id=”sort_order” value=”" />
</form>

</body>
</html>

* UPDATE *

Someone asked how to update the database using ColdFusion, so here is the code:

<!--- strip the 'section_id_' from the list, so that we only have a list of ids --->
<cfset form.sort_order = ReplaceNoCase(form.sort_order, "section_id_", "", "all") />

<cfloop from="1" to="#ListLen(form.sort_order)#" index="ndx">
  <cfquery name="qryOrder" datasource="#Request.Datasource#">
    update [Sections] set
      section_order = <cfqueryparam value=”#ndx#” cfsqltype=”cf_sql_integer” />
    where section_id = <cfqueryparam value=”#ListGetAt(form.sort_order, ndx)#” cfsqltype=”cf_sql_integer” />
  </cfquery>
</cfloop>

Force file download

Filed under: ColdFusion — aliaspooryorik @ 11:11 am

To force a file to download instead of opening in the browser use this code:

<cfset variables.filepath = ExpandPath('myfolder') & variables.myfile />

<cfswitch expression="#LCase(ListLast(variables.myfile, "."))#">
  <cfcase value="avi">
    <cfset variables.contentType = "video/x-msvideo" />
  </cfcase>
  <cfcase value="doc">
    <cfset variables.contentType = "application/msword" />
  </cfcase>
  <cfcase value="exe">
    <cfset variables.contentType = "application/octet-stream" />
  </cfcase>
  <cfcase value="gif">
    <cfset variables.contentType = "image/gif" />
  </cfcase>
  <cfcase value="jpg,jpeg">
    <cfset variables.contentType = "image/jpg" />
  </cfcase>
  <cfcase value="mp3">
    <cfset variables.contentType = "audio/mpeg" />
  </cfcase>
  <cfcase value="mov">
    <cfset variables.contentType = "video/quicktime" />
  </cfcase>
  <cfcase value="mpe,mpg,mpeg">
    <cfset variables.contentType = "video/mpeg" />
  </cfcase>
  <cfcase value="pdf">
    <cfset variables.contentType = "application/pdf" />
  </cfcase>
  <cfcase value="png">
    <cfset variables.contentType = "image/png" />
  </cfcase>
  <cfcase value="ppt">
    <cfset variables.contentType = "application/vnd.ms-powerpoint" />
  </cfcase>
  <cfcase value="wav">
    <cfset variables.contentType = "audio/x-wav" />
  </cfcase>
  <cfcase value="xls">
    <cfset variables.contentType = "application/vnd.ms-excel" />
  </cfcase>
  <cfcase value="zip">
    <cfset variables.contentType = "application/zip" />
  </cfcase>
  <cfdefaultcase>
    <cfset variables.contentType = "application/unknown" />
  </cfdefaultcase>
</cfswitch>

<cfheader name="Content-disposition" value="attachment;filename=#variables.myfile#" />
<cfcontent type="#variables.contentType#" file="#variables.filepath#" />

February 26, 2008

A ColdFusion 9 Suggestion

Filed under: ColdFusion — aliaspooryorik @ 3:54 pm

Please can we have the same functionality as the cfoutput group attribute in cfloop. For example:

<cfloop query="qryFoo" group="mycolumn">
  <cfloop>
  </cfloop>
</cfloop>

Thanks Adobe!

Next Page »

Blog at WordPress.com.