0
votes

I have a cfc function that accepts a query type argument (with the intent of running a query of query). I am able to call the function successfully using <cfinvoke>. However, what I really want to do is call the function from a hidden <cfinput>'s bind attribute, using bind="cfc:cfcname.somefunction(queryVar)", and that code fails. There is no visible error, but it doesn't look like my function ever gets called - I have a cflog in there. [The reason for the bind is not really relevant to my question, but it is because I need the function call to react to another control on the form - I've distilled all that out of my question]

If I replace the queryVar with some string variable, the function gets called fine, but obviously I cannot get the results I want without passing the query in. If I use bind="cfc:cfcname.somefunction(#queryVar#)", I get a

"Complex type cannot be converted to simple type"

error. I've searched for any documented restriction on passing query (or any complex type) to a cfc from a bind, but haven't found a clue.

1
You say that the function has to react to another control on the page. If you are referring to user input then you have to realize that by the time this happens, no Cold Fusion variables of any type exist, except for those in the session or application scope. I think you have to rethink your approach. - Dan Bracuk
Dan is correct. Binding of input forms happens on the client side, not the server. At that point there is no ColdFusion query variable available. If you want data available from your query for the user to select, then you will need to loop over your query while generating the page before delivery to the user's browser. This reference might help you understand. - Miguel-F
Thanks Dan, Miguel. - user14979990
Thanks @DanBracuk, Miguel. I had already read the reference you provided, Miguel, but thanks. The ColdFusion variables are, however, available at page execution time, so in theory a representation of the cfqeury could have been passed to the bind expression - I believe my approach would work if it was a simple string variable, which makes the error message about complex type conversion more meaningful. I will test and post back. (I feel like you folks might have missed my comment about the bind usage being orthogonal to the question.) - user14979990
Please elaborate your question so we can better help you. Seeing more of the code you are testing would likely help. A query object cannot be used in the bind attribute of the cfinput tag. That is why you are getting the error. - Miguel-F

1 Answers

1
votes

You can use "bind" to send user-inputted data to another page for processing then send back the results. For example, If you use "bind" on a Birthdate field. When the user selects their birthdate, you can send that date to a CFC or CFM page and have it do the math #DateDiff('yyyy',birthdate,Now())# and return the result, which would be how many "years old" the user is.

But to my knowledge, you can't send a query to another page via the "bind" function. However, you could run the query again on another page and return the results.

Or perhaps look into JQuery to handle further processing after the page has loaded.