• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Bound CFSelect not working (with or without search box)

New Here ,
Jul 26, 2011 Jul 26, 2011

Copy link to clipboard

Copied

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

TOPICS
Advanced techniques

Views

727

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 02, 2011 Aug 02, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 05, 2011 Aug 05, 2011

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 05, 2011 Aug 05, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 05, 2011 Aug 05, 2011

Copy link to clipboard

Copied

I just saw that today too! FWIW: I wish there were a "OnCFMRequest" instead. IMHO that would be more useful. What would need to be added/done to every method in a cfc? Especially when I specify a return type.

I only found the out about the issue when the CFAjax,js error started showing up and I found the bug report. The description led me to believe that Application.cfc didn't process cfincludes correctly somehow. I'm not even sure of it's a "Bug" in the traditional sense.

I feel like I need to prepare the page structure way before the meat of the request is processed.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 05, 2011 Aug 05, 2011

Copy link to clipboard

Copied

LATEST

I just saw that today too! FWIW: I wish there were a "OnCFMRequest" instead. IMHO that would be more useful. What would need to be added/done to every method in a cfc? Especially when I specify a return type.

Ah, well onCfcRequest was implemented as a fix for the fact that when one has an onRequest handler, it buggered up any CFC request.  It's only reason for being is to block onRequest from running in those situations.

I only found the out about the issue when the CFAjax,js error started showing up and I found the bug report. The description led me to believe that Application.cfc didn't process cfincludes correctly somehow. I'm not even sure of it's a "Bug" in the traditional sense.

It's not a bug.  It's just an artifact of on oversight on the part of CF when onRequest was first implemented.

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation