Using Related or Dependent Select With Lucee

Hello Community,

I just shifted from ColdFusion 9 to Lucee 5.3.8.206. I’am in the process of shifting all my apps. During this shifting I am facing some issues so a request to the community to help me out.

Recently I am facing the Related Select or Dependent Select problem. The CFSELECT in Lucee does not support BIND attribute. Any Idea how to overcome this problem.

My CFC

<cffunction name="GetRoles" access="remote" returnType="any">
	<cfquery name="lstRoles" datasource="#request.dsn#">
              SELECT  '' AS role_id, '--- ALL ---' AS role_name
             UNION ALL
             SELECT role_id, role_name 
             FROM   SUS_INDX_ROLE
             ORDER BY role_id ASC
	</cfquery>
	<cfreturn lstRoles>
</cffunction>

<cffunction name="getSubRoles" access="remote" returnType="any">
<cfargument name="SUS_INDX_ROLE" type="any" required="true">
	<cfif ARGUMENTS.SUS_INDX_ROLE EQ "">
	<cfelse>
		<cfquery name="LstSubRoles" datasource="#request.dsn#">
			SELECT Sub_Role_Id, Role_id, Sub_Role_Name
			FROM SUS_INDX_SUB_ROLE
			WHERE Role_id = #ARGUMENTS.SUS_INDX_ROLE#
			ORDER BY Role_id
		</cfquery>
	</cfif>
	<cfreturn LstSubRoles>
</cffunction>

My Form



Select Role (Optional):



       <div class="control-group">
    	<label class="control-label" for="title_id">Select Sub Role:</label>
	<div class="controls">
    	<cfselect name="SelSubRole" bind="cfc:Places.getSubRoles({SelRole})"
	display="Sub_Role_name" value="Sub_role_Id" bindOnLeoad="true"/>
	</div>
</div>

Regards

Hi @fusioner, welcome!

There are certain tags in cfml that the own CF community discourages. The cause: they generate HTML and JavaScript that isn’t very flexible. In the link above you can see from older articles how to switch to real HTML selects. We really encourage you to do so.

Also, two weeks ago I’ve helped a user on Stack-Overflow creating an AJAX request with jQuery and CFML. Maybe that example can help as a start. There is also another user (@sos) who added an example of retreiving data from a cfc component with pure data. It’s worth to take a look at.

2 Likes

Hi,

That being said, if you are not strong with ajax then look at the HTML5 datalist attribute.

What I did with a lot of code like this was just query everything before the page renders, then push everything into the datalist.

The second option would be flex-datalist.

1 Like

Also, make always sure to use cfqueryparam to prevent SQL injection.

2 Likes

Found a good solution using jQuery and Ajax

But the code has 2 errors.

  1. The first function does not has a CFRETURN Tag.
  2. The Second CFUNCTION is missing an access type attribute which should be “remote”.

The rest of the code is great.

1 Like