Skip to main content
Participant
July 26, 2011
Question

Bound CFSelect not working (with or without search box)

  • July 26, 2011
  • 1 reply
  • 798 views

Hello,

I'm on WS2008 (64-bit) with IIS and CF9.0.1 (32 bit) and can't seem to get a bound CFSelect to work at all. CFGrid and other AJAX contriols work great. The code (shown below) appears to run without errors but the option tags are never generated.The binding CFC method returns a query with the data I want (I can see it on a dump) but is dropped by CF somehow.

Ideally I want to use this approach on several complex forms but need to get something working first. Removing the lookup doesn't help either. I'm pulling this Oracle data via the 10G Client's ODBC driver.

I've been working on CF forever (4-9) and never was stumped like this. Otherwise CF 9 On this server is running without a hitch.

Long term I'm trying to move away from our Flash/Actionscript equivilants and move toward AJAX. But I'm stuck. Please help!

Thanks

Tim

Index.cfm

__________________________________________________

<cfparam name="form.lookup" type="string" default="A">
<cfform preservedata="Yes">
    Search: <input type="text" name="lookup" id="lookup"><br />
    <cfselect name="Emp" bind="cfc:application.getEmpList({lookup})" value="EMPL_NBR" display="EMPL_NM">
        <option value="00000000">--- No Employees ---</option>
    </cfselect>
</cfform><br>
<!--- Just for Testing --->
<cfinvoke component="Application" method="getemplist" returnVariable="qRead">
<cfinvokeargument name="likename" value="#form.lookup#">
</cfinvoke>
<cfdump var="#qRead#" output="browser">

Application.cfc

_____________________________________________________

<cffunction name="getEmpList" access="remote" returntype="query" output="yes">
    <cfargument name="LikeName" type="string" required="yes"> 
    <cfquery name="Emps" datasource="#application.dsn#" maxrows=50>
        Select EMPL_NBR, EMPL_NM from MNDOT_EMPLOYEE
        Where EMPL_STAT_CD = 'A'  <cfif isdefined("LikeName")> and upper(Empl_Nm) like '%#ucase(likename)#%'</cfif>
        Order By Empl_NM</cfquery>
    <cfreturn emps>
</cffunction>

Message was edited by: CFTim1965

Message was edited by: CFTim1965

This topic has been closed for replies.

1 reply

CFTim1965Author
Participant
August 2, 2011

Update: If I remove our template (stardards from our CO) all works well. It won't generate the Javascript if the template is used.

CFTim1965Author
Participant
August 5, 2011

Turns out that bound (used for the CF AJAX tags) CFCs are processed by the Application.cfc event methods like CFMs are and will have any HTML tags added in. When my method returned the query it had all my template code at the top (and some on the bottom). I used the code (in the Application.cfc) below to only write the HTML when the CFM pages are processed. Hope this helps! There a lot of misleading half truths out the about this issue.

<cffunction name="onRequestStart">
    <cfargument name="targetpage" type="string" required="true">
    <cfset var isCFM  =  (lcase(ListLast(arguments.targetPage, '.')) eq 'cfm') />
    <cfif isCFM>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
          ...
        <body>
        <cfset AppHeader() /><!---  Create the Template Header --->
    </cfif>
</cffunction>

Inspiring
August 5, 2011

I don't think it's a very good idea to output mark-up in the event handler methods (or, indeed, any method).  onRequestStart() is better used for setting up variable values specific to a request, but leave view CFM templates to handle mark-up.  If I had to output mark-up in Application.cfc, I'd use onRequest instead of onRequestStart.

Incidentally, if you're running CF9, you should implement a onCfcRequest handler - http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSe821657cd7d6f83f6daaa733122cf6931bb-8000.html - which will be called instead of onRequest.

There a lot of misleading half truths out the about this issue.

Such as?

--

Adam