I'm trying to use a bind with the remoting service, but get the error
values must be a struct. Since bind's use the {} syntax, it says I
must escape any uses of {} that aren't binds. Can anyone lead me to
the right syntax to use this bind?
bind="cfc:mg.RemotingService.executeEvent(eventName='cservice.search',
values={txtSearch@keyup})"
Otherwise I'll probably have to create another function in the
RemotingService cfc that simply passes the arguments to values.
--
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog
You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to model...@googlegroups.com
To unsubscribe from this group, send email to
model-glue+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en
--
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog
You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to model...@googlegroups.com
To unsubscribe from this group, send email to
model-glue+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en
Should I make a similar executeBind in AbstractRemotingService, but if
I
wanted to bind to a cfgrid vs the above text box, what is the proper
return?
--
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog
You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to model...@googlegroups.com
To unsubscribe from this group, send email to
model-glue+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en
But with a Bind expression, you want only a single value returned. I
got my code to work, but had to create these functions, and modify my
form like...
<cfform name="frmList">
<cfinput name="txtSearch" type="text" value="">
<cfinput name="txtResult" type="text"
bind="cfc:mg.RemotingService.executeBindEvent
(eventName='cservice.search', values={txtSearch@keyup})">
</cfform>
The RemotingService has this new function,
<!--- pass in your values is name=value pairs to the function, all are
passed as the
arguments structure to the super.executeBindEvent() --->
<cffunction name="executeBindEvent" output="false" access="remote"
returntype="any">
<cfargument name="eventName" type="string" required="true" />
<cfargument name="returnValue" type="string" required="false"
default="result" />
<cfreturn super.executeBindEvent(arguments.eventName, arguments,
arguments.returnValue) />
</cffunction>
In AbstractRemotingService.cfc I added this function,
<cffunction name="executeBindEvent" output="false" access="remote"
returntype="any">
<cfargument name="eventName" type="string" required="true" />
<cfargument name="values" type="struct" required="false"
default="#StructNew()#"/>
<cfargument name="returnValue" type="string" required="false"
default="result" />
<cfset var local = StructNew()/>
<!--- For Javascript post calls to the service --->
<cfif cgi.request_method eq "post">
<cfset arguments.values = duplicate(form)/>
</cfif>
<cfset local.event = getModelGlue().executeEvent
(argumentCollection=arguments) />
<cfset local.result = local.event.getValue(returnValue) />
<cfset resetCFHtmlHead() />
<cfreturn local.result />
</cffunction>
At the moment, the form just echo's the typed text via my controller's
code, but it could be made to do lookups in the database which is to
come and via a bind to a cfgrid. More testing to come.
Just try my code, its self explanatory. If what I've done can be done
with existing MG code let me know, but I can't use a struct in a
<cfinput> bind expression and I can't use a struct in the return value
either.
--
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog
You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to model...@googlegroups.com
To unsubscribe from this group, send email to
model-glue+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en
Ultimately it doesn't matter to me, as you say I can make my own cfcs.
--
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog
You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to model...@googlegroups.com
To unsubscribe from this group, send email to
model-glue+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en
Here's an example. I didn't want to post this in that trak ticket.
From the translator example, I modified two files to make this.
frmPhrase.cfm and Controller.cfc
First the form,
<cfset translateEvent = event.GetValue('xe.translate')>
<cfform name="frm">
<p>
Enter text to translate: <cfinput type="text" name="txtPhrase"
value="" />
Translation: <cfinput type="text" name="result"
bind="cfc:translator.RemotingService.executeBindEvent(
eventName='#translateEvent#', phrase={txtPhrase@keyup})" >
</p>
</cfform>
The controller function
<cffunction name="TranslatePhrase" access="public" returntype="void"
output="no">
<cfargument name="event" type="any">
<cfset var phrase = arguments.event.getValue("phrase") />
<cfset var result = beans.translator.translate(phrase) />
<cfif not len(trim(phrase))>
<cfset arguments.event.SetValue("result", "Please enter a phrase
to translate.")>
<cfelse>
<cfset arguments.event.SetValue("result", result)>
</cfif>
<cfset arguments.event.addTraceStatement("TranslatePhrase
Results", result) />
</cffunction>
I tried using a bind on a cfdiv, but it kept sending two commas even
if the text box was empty. I couldn't figure it out. As a result,
the translation text box is too short to display the full error
message, but at least you can see it working.
The code for the eventBindEvent() in RemotingService.cfc is the same
as posted above.
This may not be an approach you wish to take, but it is possible to
achieve the same result without modifying the RemotingService by using
a cfajaxproxy bind instead:
<cfset translateEvent = event.GetValue('xe_translate')>
<cfajaxproxy bind="url:RemotingService.cfc?method=executeEvent&returnformat=json&eventName=#translateEvent#&returnValues=translatedPhrase&phrase={txtPhrase@keyup}"
onsuccess="setResult" />
<script type="text/javascript">
<!--
function setResult(returnValue) {
document.getElementById('result').value = returnValue.translatedPhrase;
}
//-->
</script>
<cfform name="frm">
<p>
Enter text to translate: <cfinput type="text" name="txtPhrase" value="" />
Translation: <cfinput type="text" name="result" id="result" />
</p>
</cfform>
--
Ezra Parker
Hi Chuck,
This may not be an approach you wish to take, but it is possible to
achieve the same result without modifying the RemotingService by using
a cfajaxproxy bind instead:
<cfset translateEvent = event.GetValue('xe_translate')>
<cfajaxproxy bind="url:RemotingService.cfc?method=executeEvent&returnformat=json&eventName=#translateEvent#&returnValues=translatedPhrase&phrase={txtPhrase@keyup}"
onsuccess="setResult" />
<script type="text/javascript">
<!--
function setResult(returnValue) {
document.getElementById('result').value = returnValue.translatedPhrase;
}
//-->
</script>
<cfform name="frm">
<p>
Enter text to translate: <cfinput type="text" name="txtPhrase" value="" />
Translation: <cfinput type="text" name="result" id="result" />
</p>
</cfform>
--
Ezra Parker