Form Selection Data Dependencies

15 views
Skip to first unread message

jarerrac

unread,
Oct 4, 2010, 2:57:17 PM10/4/10
to Mach-II for CFML
I am creating a simple form page with dropdowns that have dependencies
on each other. Let's take the example of countries, states, and
cities. If I have these three dropdowns in my form, changing the
country will change the data in the states and cities dropdown.
Changing the state dropdown will change the data in the cities
dropdown. I know how to do this using AJAX, but how does this fit into
the mach-ii framework? Would the onclick/onchange event on the
dropdowns trigger a mach-ii event? How? location.href? form submit?
How would the event structure be organized? I know this is a common
problem but I'm new to the framework. Any help would be appreciated.

Thanks.

Kurt Wiersma

unread,
Oct 8, 2010, 4:56:11 PM10/8/10
to mach-ii-for...@googlegroups.com
I would recommend either checking out the new endpoint features in 1.9
BER or setting up a Mach II event which will handle responding your
ajax call. Another option would be to call a RemoteFacade CFC setup
via ColdSpring. That way you can have it return JSON by using CF 8+'s
serializeToJSON function.

--Kurt

> --
> You received this message because you are subscribed to Mach-II for CFML list.
> To post to this group, send email to mach-ii-for...@googlegroups.com
> To unsubscribe from this group, send email to mach-ii-for-coldf...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/mach-ii-for-coldfusion?hl=en
>
> ***New URLs as of April 29th, 2010***
> SVN: http://svn.mach-ii.com/machii/
> Wiki / Documentation / Tickets: http://trac.mach-ii.com/machii/
>

jlcox

unread,
Oct 11, 2010, 9:08:58 AM10/11/10
to Mach-II for CFML
> Another option would be to call a RemoteFacade CFC setup
> via ColdSpring.

Kurt, can you elaborate on this? Right now I'm doing Ajax calls
through a proxy object that references the services created by
ColdSpring through application.service Factory, i.e.,

<cfcomponent output="false" hint="Used by jQuery Ajax getJSON function
calls" displayname="proxy Service">
<cfsetting showdebugoutput="no" enablecfoutputonly="yes"/>
<cfcontent reset="yes" />
<!---ColdSpring--->
<cfset variables.sf = application.serviceFactory />
<!--- general-purpose proxy function...will pass through any method
and arguments thrown at it to the underlying service --->

<cffunction name="proxy" access="remote" returntype="any"
output="false">
<cfargument name="service" type="string" required="yes"/>
<cfargument name="remotemethod" type="string" required="yes"/>
<cfset var svc = variables.sf.getBean(arguments.service) />
<cfset var outvar = 0 />
<cfinvoke component="#svc#" method="#arguments.remoteMethod#"
argumentcollection="#arguments#" returnvariable="outVar" />
<cfreturn outVar />
</cffunction>
</component>

If I could directly call a RemoteFacade created by ColdSpring I could
avoid having to instantiate a proxy service on each call, but I'm
unclear how to reference the RemoteFacade from within jQuery.

Peter J. Farrell

unread,
Oct 11, 2010, 9:24:14 AM10/11/10
to mach-ii-for...@googlegroups.com
Here's the XML for CS 1.2:

<bean id="adminANPService_remote"
class="coldspring.aop.framework.RemoteFactoryBean">
<property name="target"><ref bean="adminANPService"/></property>
<property name="serviceName"><value>adminANPServiceRemote</value></property>
<property
name="relativePath"><value>${remotingRelativePath}</value></property>
<property
name="remoteMethodNames"><value>doesAdminNameExist</value></property>
</bean>

In this case, I also have a bean "adminANPService" in which is the
target bean for the remote facade. The value of ${remotingRelativePath}
is "/remoting" which ultimately resolves to
example.com/remoting/adminANPServiceRemote.cfc (the name of the
generated CFC is indicated in the "serviceName" property).

There's an option parameter in the CSProperty that you can add:

<parameter name="generateRemoteProxies" value="true"/>

This will look for any RemoteFactoryBean defined in your CS
configuration file and regenerate them when you reload your
application. Right now CS won't regenerate the remote proxy if the file
exists on disk. The other way of doing it is deleting the CFCs from the
remoting directory but this way is definitely easier.

Personally, I'm moving to using REST endpoints for all my AJAX proxying
in Mach-II. While the remote factory stuff in ColdSpring is good, it
doesn't offer many extension points unless you get into AOP and usually
the AOP only applies to AJAX calls. It ends up being a lot of
configuration.

REST is easier to manage for us...

<cffunction name="temp" access="public" returntype="string" output="false"
hint="Temp testing method. To be removed"
rest:uri="/temp"
rest:method="PUT">

<cfreturn "temp" />
</cffunction>

The JS (in Prototype):

new Ajax.Request("/index.cfm/dashboard.api/memory", {
method: 'DELETE'
, onCreate: function() {
currentObject.stopMemoryInformation();
currentObject.startGarbageCollectionTimer();
$('gcRun').fade({ duration: 0.5, queue: 'end' });
$('gcInProgress').appear({ duration: 0.5, queue: 'end' });
}
, onSuccess: function(transport) {
currentObject.startMemoryInformation();

currentObject.stopGarbageCollectionTimer(transport.getHeader("recoveredMemory"));
$('gcInProgress').fade({ duration: 0.5, queue: 'end' });
$('gcRun').appear({ duration: 0.5, queue: 'end' });
}
, on403:
myGlobalHandler.loginRedirect.bindAsEventListener(currentObject)
});


jlcox said the following on 10/11/2010 08:08 AM:

jlcox

unread,
Oct 11, 2010, 9:55:10 AM10/11/10
to Mach-II for CFML
I just checked out the CS version, that certainly is a lot of work,
especially with many remote function calls. I like my tiny
proxyService better.

I'll checkout the 1.9 REST endpoints. Thanks for the response.
Reply all
Reply to author
Forward
0 new messages