views:

67

answers:

1

This works with a mySQL backend

In the form...

   <cfselect name="to" size="1" bind="cfc:cfcs.messages.getOrganisations()" bindonload="yes" value="organisationID" display="organisationName" required="Yes">
     </cfselect>

in the cfc

<cffunction access="remote" name="getOrganisations" output="false" returntype="query" displayname="Get organisations list" hint="This method returns a list of organisations as a query.">
    <cfquery name="getOrganisations" datasource='myData'>

    SELECT organisationID, organisationName, acceptsReferral, metadataTemplate
    FROM organisations
    WHERE acceptsReferral
    ORDER BY organisationName ASC;

    </cfquery>
    <cfreturn getOrganisations>
</cffunction>

but if I try

<cffunction access="remote" name="getOrganisations" output="false" returntype="query" displayname="Get organisations list" hint="This method returns a list of organisations as a query.">
    <cfquery name="getOrganisations" datasource='myData'>
    SELECT '0' AS organisationID, 'Select' AS organisationName, false AS acceptsReferral, 0 AS metadataTemplate
    FROM organisations
    UNION
    (SELECT organisationID, organisationName, acceptsReferral, metadataTemplate
    FROM organisations
    WHERE acceptsReferral
    ORDER BY organisationName ASC)

    </cfquery>
    <cfreturn getOrganisations>
</cffunction>

to try and get a select leading row to the query, I get this AJAX error in firebug " JSON serialization failure: Unable to serialize binary data to JSON."

Henry's suggestion resolved the above, but I'm again slightly foxed by the next bit , trying to get two selects linked.

This works...

<cfselect name="attentionOf" size="1" bind="cfc:cfcs.messages.getOrganisationMembers({to})" bindonload="false" value="userID" display="name" required="No" queryPosition="below">
<option value="0">Select</option>
</cfselect>

...but if i try to pass in the DSN with the bound field I get "error parsing bind" from this

<cfselect name="attentionOf" size="1" bind="cfc:cfcs.messages.getOrganisationMembers({to}, 'mySqlData')" bindonload="false" value="userID" display="name" required="No" queryPosition="below">
    <option value="0">Select</option>
</cfselect> 
+1  A: 

Oh, I guess this is what you want.

<cfset organisations = createObject("component", "cfcs.messages").getOrganisations()>

<cfselect name="to" query="organisations" 
          value="organisationID" display="organisationName"
          required="Yes" queryPosition="below">
    <option value="0">Select</option>
</cfselect>

If you really need it to work with bind, try if the queryPosition attribute works. If queryPosition doesn't work with bind, then u need to insert the extra dummy row. It might be easier to use union with Query of Queries.

Henry
That did it , nice job Henry. I've added my ongoing woes with the linked data bind to the OP
Saul
why would you need to pass DSN?? doesn't make sense. DSN should, usually, be in your Application scope. If you really need to pass a variable, try to set DSN = 'mySqlData' in JS, then put just DSN w/o quote in the bind expression and try?
Henry
Hmm, I was passing in the DSN to the CFC in order to avoid any dependency, as you can tell I'm a bit new to CFCs but thought it was best practice not to have any application, or session variables in the CFC itself?I'll try it as a variable without quotes
Saul
Use Remote Proxy. So, instead of just changing the function to Remote, revert it back to Public. Create a new thin CFC that contains the remote method, and uses the Appliction scope to populate things like DSN, and call the actual method for you. ColdSpring would help you in this situation, u can take a look. http://www.coldspringframework.org/coldspring/examples/quickstart/index.cfm?page=remote
Henry