919 - 926 - 9847

Bind CFGrid updates to a form field

I searched for a fairly good amount of time before figuring this out.  The background is this.

I don't usually have much use for CFGrid, at least not since the CF 4.x days.  That being said, I found myself in need of it this week for a project which I've been assigned to.  The grid was pulling data back correctly, but what it really needed to do was refresh when you select value XX from a select box.  The answer turned out to be pretty simple.  First, the form.

 


<html>
<head><title>test me</title></head>
<body>

<!--- You MUST use a CFFORM here --->
<cfform name="myProds" action="" method="post">

<!--- Our select box --->
<select name="product" id="product" class="datasectiontextlong">
    <option value="0">--Select a product--</option>
    <option value="1">Product 1</option>
    <option value="2">Product 2</option>
</select>

<!--- Our grid (notice the select box value here) --->
<cfgrid format="html"
    name="products"
    pagesize="7"
    height="200"
    width="550"
    bind="cfc:myCFC.getProds({myProds:product},{cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})"
>

    <cfgridcolumn name="ID"/>
    <cfgridcolumn name="display" header="Your Choice">
</cfgrid>

</cfform>
</body>
</html>

And the CFC

 


<cfcomponent name="myCFC" displayname="You can't touch this" output="false" >
    <!--- We use some dummy data in this instance --->
    <cffunction name="getProds" access="remote" returntype="struct">
    <cfargument name="productID" required="true" type="numeric" />
        <cfargument name="page" type="numeric" required="yes">
<cfargument name="pageSize" type="numeric" required="yes">
<cfargument name="gridsortcolumn" type="string" required="no" default="">
<cfargument name="gridsortdir" type="string" required="no" default="">
        
        <cfscript>
    var selectQuery = QueryNew("ID,display");
            var tmp=queryaddrow(selectQuery,2);
            tmp=querysetcell(selectQuery,'ID','1',1);
            tmp=querysetcell(selectQuery,'ID','2',2);
            tmp=querysetcell(selectQuery,'display','You chose wisely',1);
            tmp=querysetcell(selectQuery,'display','You chose poorly',2);
        
</cfscript>
        <cfquery name="returnQuery" dbtype="query">
            select ID,display
            from selectQuery
            where ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.productID#">
        </cfquery>
<cfreturn QueryConvertForGrid(returnQuery,
arguments.page,
arguments.pageSize)>

    </cffunction>
    
</cfcomponent>

The missing piece (for me) was that first bit in the CFGrid CFC call.  myProds.product.  If you tell the grid to pass this as a variable into the CFC function, you can then pass that into your select statement.  I presume this holds true for any form field and not just select boxes. 

How to configure a kick ass development setup - day 5

Last day!  Although, maybe we'll add some addendums.  Let's bang out the database installs.

Poof, that's it. 

So now, we're able to work on ColdFusion 9, Railo 3.3, regular HTTP, MySQL and MSSQL.  I'll probably through in a PHP portion down the line, but we'll just see what I end up having time for.

Coming up in the near future, how to set up a kick ass Development server on Ubuntu!

How to configure a kick ass development setup - day 4

On our plate today, we'll be installing Apache.  I'm using the 2.2.x branch.

  • Go and grab your .msi, I'd recommend the one with OpenSSL included.  http://httpd.apache.org/download.cgi#apache22
  • Install Apache to c:\cf_dev\apache.  You'll need to choose "custom install" to change the directory. The other values can be left at default.
  • Get CF9 hooked up to Apache, Start-> All Programs-> Adobe-> CF9 xxxx-> Web Server Configuration Tool
  • Click Add... to create a new connector
  • Choose the CFusion instance and select Apache as your web server.  You'll need to pick out the configuration directory (c:\cf_dev\apache\conf) and the binary object (c:\cf_dev\apache\bin\httpd.exe) and check "install CF9 services".
  • Edit c:\cf_dev\apache\conf\httpd.conf and add at the bottom (the include pulls in any files we add to dev folder):
    #Turn on virtualhosts
    NameVirtualHost *:80
    NameVirtualHost *:443

    Include c:/cf_dev/apache/conf/dev/*.conf

    <Files ~ ".hbmxml$">
    Order allow,deny
    Deny from all
    </Files>
  • Find DirectoryIndex in the httpd.conf file, and add index.cfm to it.
  • Create a new site vhost file, we'll start with site1 (from back on day 1).  Create it as c:\cf_dev\apache\conf\dev\site1.conf
  • Fill it like so:
    #site1
    <VirtualHost *:80>
    <Directory "C:\cf_dev\projects\site1">
        AllowOverride None
        Options None
        Order allow,deny
        Allow from all
    </Directory>

    alias /CFIDE C:\JRun4\servers\cfusion\cfusion-ear\cfusion-war\CFIDE
    alias /cfide C:\JRun4\servers\cfusion\cfusion-ear\cfusion-war\CFIDE

     # JRun Settings
    <IfModule mod_jrun22.c>
        JRunConfig Verbose false
        JRunConfig Apialloc false
        JRunConfig Ignoresuffixmap false
        JRunConfig Serverstore "C:/JRun4/lib/wsconfig/1/jrunserver.store"
        JRunConfig Bootstrap 127.0.0.1:51020
        AddHandler jrun-handler .jsp .jws .cfm .cfml .cfc .cfr .cfswf
    </IfModule>   

     DocumentRoot "C:\cf_dev\projects\site1"
     ServerName site1.local
     ServerAdmin contact@localhost
    </VirtualHost>
  • Note, you should now remove all but LoadModule jrun_module "C:/JRun4/lib/wsconfig/1/mod_jrun22.so" from c:\cf_dev\apache\conf\httpd.conf.  This will allow us to use multiple J2EE engines under the same apache config.
  • Edit http.conf, and uncomment:
    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
  • Create a Railo based site for Site2 (follow the steps found on day one to first create the site2 project), fill the c:\cf_dev\apache\conf\dev\site2.conf with (we use proxypass to hand of CFM requests):
    #site2
    <VirtualHost *:80>
    <Directory "C:/cf_dev/projects/site2">
        AllowOverride None
        Options None
        Order allow,deny
        Allow from all
    </Directory>

    <Proxy *>
                Allow from 127.0.0.1
        </Proxy>

    ProxyPreserveHost On
    ProxyPassMatch  ^/(.+\.cf[cm])(/.*)?$  ajp://localhost:8009/$1$2

     DocumentRoot "C:/cf_dev/projects/site"
     ServerName site2.local
     ServerAdmin contact@localhost
    </VirtualHost>
  • To make Tomcat aware of server, we need to add this just before the </engine> tag at the end of c:\cf_dev\tomcat6\conf\server.xml.  It seems like duplication, but it just MUST be done:
    <Host name="site2.local" appBase="webapps" unpackWARs="false" autoDeploy="false" xmlValidation="false" xmlNamespaceAware="false">
              <Context path="" docBase="C:/cf_dev/projects/site2" />
        </Host>
  • Edit your hosts file (mine is at C:\Windows\System32\drivers\etc\hosts) to locally route our requests to the correct place.
    127.0.0.1 site1.local
    127.0.0.1 site2.local

How to configure a kick ass development setup - day 3

Today, we'll deploy Railo on Tomcat 6.  Note, I'm doing this the "hard way".  Jorden, from viviotek, created a handy dandy installer.  But, I rather like to install this stuff by hand so I can know what to fix should it break.  Pretty much all of this info is gleaned from Sean Corfield and his blog about installing various bits and pieces.  You can find it here.

  • Grab Tomcat 6 from http://tomcat.apache.org/download-60.cgi. I used the Core:32-bit windows zip
  • Edit your JAVA_HOME environment variable to point to c:\cf_dev\<jdk you downloaded previously>
  • Unzip it to c:\cf_dev and rename the folder to tomcat6
  • Go grab the Railo JAR files from http://www.getrailo.org/index.cfm/download/.  
  • Unzip these files to c:\cf_dev\tomcat6\railo
  • Open up c:\cf_dev\tomcat6\conf\catalina.properties and find common.loader=.  Add ${catalina.home}/railo,${catalina.home}/railo/*.jar to that line.
  • Open up c:\cf_dev\tomcat6\conf\web.xml At the end of the servlet section, just before the servlet-mapping section, add the following:
    <servlet>
       <servlet-name>RailoCFMLServlet</servlet-name>
       <description>CFML runtime Engine</description>
       <servlet-class>railo.loader.servlet.CFMLServlet</servlet-class>
       <init-param>
    <param-name>configuration</param-name>
    <param-value>/WEB-INF/railo</param-value>
    <description>Configuration directory</description>
    </init-param>  
       <!-- init-param>
    <param-name>railo-server-root</param-name>
    <param-value>.</param-value>
    <description>directory where railo root directory is stored</description>
    </init-param -->
       <load-on-startup>1</load-on-startup>
    </servlet>  
    <servlet>
       <servlet-name>RailoAMFServlet</servlet-name>
       <description>AMF Servlet for flash remoting</description>
       <servlet-class>railo.loader.servlet.AMFServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
    </servlet>  
    <servlet>
       <servlet-name>RailoFileServlet</servlet-name>
       <description>File Servlet for simple files</description>
       <servlet-class>railo.loader.servlet.FileServlet</servlet-class>
       <load-on-startup>2</load-on-startup>
    </servlet>
  • At the end of the servlet-mapping section, just before the filter section, add the following:
    <servlet-mapping>
       <servlet-name>RailoCFMLServlet</servlet-name>
       <url-pattern>*.cfm</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
       <servlet-name>RailoCFMLServlet</servlet-name>
       <url-pattern>*.cfml</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
       <servlet-name>RailoCFMLServlet</servlet-name>
       <url-pattern>*.cfc</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
       <servlet-name>RailoAMFServlet</servlet-name>
       <url-pattern>/flashservices/gateway/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
       <!-- could be RailoFileServlet -->
       <servlet-name>default</servlet-name>
       <url-pattern>/</url-pattern>
    </servlet-mapping>
  • At end of the file, add index.cfmto the list of "welcome files".
  • Open a command prompt, and run c:\cf_dev\tomcat\service.bat install to create a handy windows service

That's it!  We now have Tomcat + Railo rolling on our machine.  We're still missing the site definition, but that's a task we'll handle after we have Apache up and running.

How to configure a kick ass development setup - day 2

The next step on our journey is to install Adobe ColdFusion 9.x in the multi-server configuration. 

  • Download the installer from https://www.adobe.com/cfusion/tdrc/index.cfm?product=coldfusion.  You WILL need an Adobe ID, but it's free to sign up.  If it's not version 9.01, be sure to grab that update as well.
  • If you don't already have it, you'll need to install the .NET framework (required for the install to complete). http://www.microsoft.com/download/en/confirmation.aspx?id=22
  • As mentioned previously, we want to use the multiserver install option after running the .exe, and make sure to configure internal web server (we'll address the connector later).  Also, the developer edition will be fine for our purposes.  The path I chose was c:\cf_dev\jrun.  Install whatever options you want, but keep in mind they're a pain to get in after the fact.
  • If you need to run the 901 (or other) updater, you need to stop services before hand.  The two main ones are Macromedia JRun Admin and Macromedia JRun CFusion need to be stopped.  There's also going to be several "ColdFusion" related services that need to be stopped.  You can go ahead and set the Admin instance of ColdFusion to manual, as we'll only use that if we want to add a new CF instance.

Optional

  • If you're feeling adventurous, grab a CF8,7,6 installer.  Choose the last option of a ColdFusion EAR/WAR (EAR specifically).  Choose the install location to be c:\cf_dev\jrun4\servers\<someinstance>.
  • Manually open your unzipping program (winzip works), extract c:\cf_dev\jrun4\servers\<someinstance>\cfusion-ear out to the folder cfusion-ear.  Go into cfusion-ear and extract cfusion-war out to cfusion-war and META-INF.
  • The XML file in META-INF will be wrong, you need to change it so it looks like:
    <code>
    <?xml version="1.0" encoding="ISO-8859-1"?>

    <!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN" "http://java.sun.com/dtd/application_1_3.dtd">

    <application>

      <display-name>cfusion-ear</display-name>

        <module>
          <web>
            <web-uri>cfusion-war</web-uri>
            <context-root>/</context-root>
          </web>
        </module>
    </application>
    </code>
  • Start that Admin instance back up, and log into it at localhost:8000, and use the user "admin" and password <whatever you set the default cf password at>.
  • Click the "create a new server" link.  The server name MUST match the folder name you created in step 1.  Ports and such can be left the same.
  • Create a service for this bugger, bring up a command prompt and run c:\cf_dev\jrun4\bin\jrunsvc -install <foldername> <foldername> "Macromedia JRun <foldername> Server" "Macromedia JRun <foldername> Server" -config <path to jvm.config if you want different JVM settings, which you'll need for older CF versions, JVMs are not going to be compatible>
  • Start the service, and be happy.

How to configure a kick ass development setup - day 1

I thought it'd be fun to put out a series of setting up a development environment on you local machine. 

Once upon a time, 10 years ago, all of my development was done from a desktop machine and hosted on a staging version of our website.  That's nice and all, and it worked because I was an army of just one.  Somewhere in the mid piont of the 2000s, it became apparent that I'd need to start hosting this stuff locally, and so began my neverending journey to the perfect dev setup on my laptop.  I'll lay out what I presently use, and maybe someone can take solace in my work.  I've geared this towards windows as, well, it's what I use.  Most of the same information applies to other OS's, but it's not something I can tackle this time around.

The basics we'll go through will be:

  • Eclipse - for developing code, CSS, XML, JS, etc.
  • Java JDK  6 - required for Eclipse
  • CFEclipse - CFML IDE plugin for eclipse
  • Subclipse - plugin to eclipse for talking to subversion
  • Aptana - plugin to eclipse for HTML development, CSS, JS, etc.  Also includes FTP abilities.
  • Adobe CF - Installed in multi-server mode, with CF9 and CF8 running on JRun
  • Railo - Latest Railo version on Tomcat 6
  • Apache - For serving our content.  Yes, I know, Tomcat can do this as well.  But I prefer Apache
  • IIS - Maybe.  I've mostly given up on IIS, and don't use it on any of my machines at present.
  • MySQL 5.x - database engine of choice
  • MSSQL 2008 R2 - because I've still got some clients on MSSQL.
  • Oracle - Maybe.  We'll see.  I have to use it, but you shouldn't be forced into it.

To start us off, we'll grab and configure eclipse.  As a note, everything we do will be going into c:\cf_dev.  Adjust as needed.

And we're done!  One of the nice things that the Aptana studio brings is working with both the file system, or by project, in the left hand tab.  For now, create a new project (you should see create proejct) and call it site1.  Make sure to choose the CFML type of project.  It'll default to our c:\cf_dev\projects folder.  If asked to change to the CFEclipse perspective, I choose "no" as I spend 100% of my time in the Aptana perspective.  We'll grab the Adobe install next time around.