Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 481
  • Last Modified:

Coldfusion dependent-dropdown list error 500

Hi experts.
I have again a problem with two dependent dropdown lists.
I have the error:There was a problem retrieving the data:
500 : Internal Server Error ,but when i test the child query (q_Nomos) with a default value for per_id i get the output without errors.
Here are the cfm and cfc.
<script type="text/javascript" src="../js/engine_micro.js"></script>
<cfinvoke component="test.com.getsearchnomos" method="getPerifereia" returnvariable="q_Perifereia">
</cfinvoke>
<script language="javascript" type="text/javascript">
function getSnomos(ID){
 //set the params required for your function
 if (isNaN(ID) || ID <= 0) ID = 0;
 var param = 'perifereiaid='+ID;
 http('POST','../com/getsearchnomos.cfc?method=getmynomos', shownomos_response,param);
}
function shownomos_response(obj){
 var mySelect = document.getElementById('S_Nomos');
 mySelect.options.length = 0;

 for (var c = 0; c < obj.nomos_id.length; c++)
 {
  //note that jsmx calls always return lower case
  mySelect.options[c] = new Option(obj.nomos_text[c] , obj.nomos_id[c]);
 }      
}
</script>
<cfform>
<cfselect name="S_Perifereia" class="selectleftbig" id="S_Perifereia" onchange="getSnomos(this.value);">
                          <option value="">beliebig</option>
                          <cfoutput query="q_Perifereia">
                            <option value="#q_Perifereia.per_id#">#q_Perifereia.Per_Text#</option>
                          </cfoutput>
                          </cfselect><br />
          <cfselect name="S_Nomos" class="selectleftbig" id="S_Nomos">
             <option value="">Erst Perifereia w&auml;hlen</option>
          </cfselect>
      </cfform>

cfc:
<cfcomponent output="false">
 <cffunction name="getPerifereia" returntype="query">
  <cfset VAR qPerifereia = "">
  <cfparam name="cookie.lang" default="de">
  <cfset vlangid = #cookie.lang# >
  <cfquery name="qPerifereia" datasource="#request.dsn#">
  SELECT Per_id, Per_Text
  FROM dbo.Perifereia
  WHERE <cfif #vlangID# EQ 'gr'>
  LANGID = <cfqueryparam cfsqltype="cf_sql_varchar" value="gr">
   <cfelse>
  LANGID = <cfqueryparam cfsqltype="cf_sql_varchar" value="de">
  </cfif>
  ORDER BY per_id ASC
  </cfquery>
  <cfreturn qPerifereia>
  </cffunction>
 
 <cffunction name="getmynomos" access="remote" output="false" returntype="query" hint="Returns a query of the submenu items based on the parent menu ID">
  <cfargument name="perifereiaid" required="yes" type="numeric" hint="The parent ID of the items to return">
  <cfset var QGetNomos="">
  <cfquery name="q_Nomos" datasource="#request.dsn#">
  SELECT Nomos_Text ,Nomos_ID
  FROM dbo.Nomos
  WHERE Per_ID = <cfqueryparam cfsqltype="cf_sql_numeric" value="#ARGUMENTS.perifereiaid#">
  AND <cfif #vlangID# EQ 'gr'>
  LANGID = <cfqueryparam cfsqltype="cf_sql_varchar" value="gr">
  <cfelse>
  LANGID = <cfqueryparam cfsqltype="cf_sql_varchar" value="de">
   </cfif>
  ORDER BY Nomos_Text ASC
  </cfquery>

  <cfreturn QGetNomos>
 </cffunction>

</cfcomponent>
Any help?
0
Panos
Asked:
Panos
  • 6
  • 6
2 Solutions
 
azadisaryevCommented:
> AND <cfif #vlangID# EQ 'gr'>

where is that vlangID variable coming from??? you are not passing it in as an argument, and you are not setting it as a local function var...

Azadi
0
 
azadisaryevCommented:
that's from the getmynomos cfc function, btw...

Azadi
0
 
PanosAuthor Commented:
HI again azadi
I did use these queries without problem but not in a compnent.I don't how to use these cfif in components and cffunctions
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
PanosAuthor Commented:
getmynomos?
0
 
azadisaryevCommented:
the problem is - your cfc function has no idea about the vlangID variable in the page you called the function from unless you pass the value of that var to the function.

you have the code for it in your other function in your cfc:

<cfparam name="cookie.lang" default="de">
  <cfset vlangid = #cookie.lang# >

why don;t you try same code in the other function?

PS: that really should be <cfset VAR vlangid = cookie.lang>

Azadi
0
 
PanosAuthor Commented:
Now i have:
<cfcomponent output="false">
 <cffunction name="getPerifereia" returntype="query">
  <cfset VAR qPerifereia = "">
  <cfset Var vlangid = cookie.lang>
  <cfquery name="qPerifereia" datasource="#request.dsn#">
  SELECT Per_id, Per_Text
  FROM dbo.Perifereia
  WHERE <cfif #vlangID# EQ 'gr'>
  LANGID = <cfqueryparam cfsqltype="cf_sql_varchar" value="gr">
   <cfelse>
  LANGID = <cfqueryparam cfsqltype="cf_sql_varchar" value="de">
  </cfif>
  ORDER BY per_id ASC
  </cfquery>
  <cfreturn qPerifereia>
  </cffunction>
 
 <cffunction name="getmynomos" access="remote" output="false" returntype="query" hint="Returns a query of the submenu items based on the parent menu ID">
  <cfargument name="perifereiaid" required="yes" type="numeric" hint="The parent ID of the items to return">
  <cfset var QGetNomos="">
  <cfset Var vlangid = cookie.lang>
  <cfquery name="q_Nomos" datasource="#request.dsn#">
  SELECT Nomos_Text ,Nomos_ID
  FROM dbo.Nomos
  WHERE Per_ID = <cfqueryparam cfsqltype="cf_sql_numeric" value="#ARGUMENTS.perifereiaid#">
  AND <cfif #vlangID# EQ 'gr'>
  LANGID = <cfqueryparam cfsqltype="cf_sql_varchar" value="gr">
  <cfelse>
  LANGID = <cfqueryparam cfsqltype="cf_sql_varchar" value="de">
   </cfif>
  ORDER BY Nomos_Text ASC
  </cfquery>

but i have the same error.
End the other problem is that i can't write the cfparam befor the cfset because the cfset var... must be in the top of the function(i got this message so i did not write it at all)
0
 
srikanthmadishettiCommented:
I have not seen your requirement clearly but as far i understand  you want to display child on select of parent

like display all the cities in second select when state is selected at top .


Here is the simple one

html>
<head>
</head>
<body>
<cfform name="mycfform">
    <!---
        The States selector.
        The bindonload attribute is required to fill the selector.
    --->
    <cfselect name="state" bind="cfc:bindFcns.getstates()" bindonload="true">
        <option name="0">--state--</option>
    </cfselect>
    <cfselect name="city" bind="cfc:bindFcns.getcities({state})">
        <option name="0">--city--</option>
    </cfselect>
</cfform>
</body>
</html>



ur bindFcns cfc should have two functions getstates and getcities which should take state parameter

When you use a bind attribute to populate the selection list, the function or URL that returns the selection values must return one of the following:

A two-dimensional array, where the first element in each array row is the option value and the second element in the row is the text to display in the option list.


IF this is not what you want let me know
0
 
azadisaryevCommented:
try the attached code.

but first please check the the relative path to your cfc in the http() call in your js function is correct:
../com/getsearchnomos.cfc

there are quiet a few changes in the code below from your code, so pay attention if you are copying over your code...

Azadi

PS: will post a different code shortly, without jsmx - just with cf bindings.
<!--- CFM --->
<cfparam name="cookie.lang" default="gr">
<cfparam name="vlangid" default="#cookie.lang#">
 
<cfinvoke component="test.com.getsearchnomos" method="getPerifereia" vlangid="#vlangid#" returnvariable="q_Perifereia"></cfinvoke>
 
<script type="text/javascript" src="../js/engine_micro.js"></script>
<script type="text/javascript">
var langID = <cfoutput>'#vlangid#'</cfoutput>;
getSnomos = function(ID){
 //set the params required for your function
 if (isNaN(ID) || ID <= 0) ID = 0;
 var param = 'perifereiaid='+ID+'&vlangid='+langID;
 http('POST', '../com/getsearchnomos.cfc?method=getmynomos', shownomos_response, param);
};
shownomos_response = function(obj){
 var mySelect = document.getElementById('S_Nomos');
 mySelect.options.length = 0;
 for (var c = 0; c < obj.nomos_id.length; c++) {
  mySelect.options[c] = new Option(obj.nomos_text[c] , obj.nomos_id[c]);
 }      
};
</script>
 
<cfform>
	<cfselect name="S_Perifereia" class="selectleftbig" id="S_Perifereia" onchange="getSnomos(this.value);">
		<option value="">beliebig</option>
		<cfoutput query="q_Perifereia">
			<option value="#q_Perifereia.per_id#">#q_Perifereia.Per_Text#</option>
		</cfoutput>
	</cfselect>
	<br />
	<cfselect name="S_Nomos" class="selectleftbig" id="S_Nomos">
		 <option value="">Erst Perifereia w&auml;hlen</option>
	</cfselect>
</cfform>
 
<!--- CFC --->
<cfcomponent output="false">
	<cffunction name="getPerifereia" returntype="query" output="false">
		<cfargument name="vlangid" required="no" type="string" default="gr">
		<cfquery name="qPerifereia" datasource="#request.dsn#">
		SELECT Per_id, Per_Text
		FROM dbo.Perifereia
		WHERE LANGID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.vlangid#">
		ORDER BY per_id ASC
		</cfquery>
		<cfreturn qPerifereia>
	</cffunction>
 
	<cffunction name="getmynomos" access="remote" output="false" returntype="query" hint="Returns a query of the submenu items based on the parent menu ID">
		<cfargument name="perifereiaid" required="yes" type="numeric" hint="The parent ID of the items to return">
		<cfargument name="vlangid" required="no" type="string" default="gr">
		<cfset var QGetNomos="">
		<cfquery name="q_Nomos" datasource="#request.dsn#">
		SELECT Nomos_Text, Nomos_ID
		FROM dbo.Nomos
		WHERE Per_ID = <cfqueryparam cfsqltype="cf_sql_numeric" value="#ARGUMENTS.perifereiaid#">
		AND LANGID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.vlangid#">
		ORDER BY Nomos_Text ASC
		</cfquery>
		<cfreturn QGetNomos>
	</cffunction>
</cfcomponent>

Open in new window

0
 
azadisaryevCommented:
here's no-jsmx approach.

Azadi
<!--- CFM --->
<cfparam name="cookie.lang" default="gr">
<cfparam name="vlangid" default="#cookie.lang#">
<cfform>
	<cfselect name="S_Perifereia" class="selectleftbig" id="S_Perifereia" bind="cfc:test.com.getsearchnomos.getPerifereia(vlangid)" bindonload="yes" value="Per_id" display="Per_Text"></cfselect>
	<br />
	<cfselect name="S_Nomos" class="selectleftbig" id="S_Nomos" bind="cfc:test.com.getsearchnomos.getmynomos({S_Perifereia}, vlangid)" bindonload="no" value="Nomos_ID" display="Nomos_Text"></cfselect>
</cfform>
 
<!--- CFC --->
<cfcomponent output="false">
	<cffunction name="getPerifereia" access="remote" returntype="query" output="false">
		<cfargument name="vlangid" required="no" type="string" default="gr">
		<cfquery name="qPerifereia" datasource="#request.dsn#">
		(SELECT 0 AS Per_id, 'Beliebig...' AS Per_Text
		FROM dbo.Perifereia)
		UNION
		(SELECT Per_id, Per_Text
		FROM dbo.Perifereia
		WHERE LANGID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.vlangid#">)
		ORDER BY Per_id ASC
		</cfquery>
		<cfreturn qPerifereia>
	</cffunction>
 
	<cffunction name="getmynomos" access="remote" output="false" returntype="query" hint="Returns a query of the submenu items based on the parent menu ID">
		<cfargument name="perifereiaid" required="yes" type="numeric" hint="The parent ID of the items to return">
		<cfargument name="vlangid" required="no" type="string" default="gr">
		<cfset var QGetNomos="">
		<cfif arguments.perifereiaid gt 0>
			<cfquery name="q_Nomos" datasource="#request.dsn#">
			SELECT Nomos_Text, Nomos_ID
			FROM dbo.Nomos
			WHERE Per_ID = <cfqueryparam cfsqltype="cf_sql_numeric" value="#ARGUMENTS.perifereiaid#">
			AND LANGID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.vlangid#">
			ORDER BY Nomos_Text ASC
			</cfquery>
		<cfelse>
			<cfquery name="q_Nomos" datasource="#request.dsn#">
			SELECT 0 AS Nomos_ID, 'Erst Perifereia w&auml;hlen' AS Nomos_Text
			FROM dbo.Nomos
			</cfquery>
		</cfif>
		<cfreturn QGetNomos>
	</cffunction>
</cfcomponent>

Open in new window

0
 
PanosAuthor Commented:
Hi srikanthmadishetti:
The problem is in the cfc and not in the cfm code.

Azadi i prefer the first way and the reason is that i handle the values "Beliebig" and "Erst Perifereia w&auml;hlen" dynamic getting the values dependet from the language i use.
(i use this solution:http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_23072100.html)
If i would use the second(no-jsmx) it would be more complicated for me(it is allready).
Now using the first code i have an error :There was a problem retrieving the data:
500 : The value returned from the getmynomos function is not of type query)
If you need here is how the table nomos is:
Nomos_ID      Per_ID     Nomos_Text      LangID
1                     1               1testde               de
1                     1               1testgr                gr
2                     1               2testde               de
2                     1               2testgr                gr
3                     2               3testde               de
3                    2                3testgr                gr

And something else.
The way from srikanthmadishetti using the default values in the cfm (<option name="">--all--</option>) and  bind to the cfc would free me from the problem with the default values.              
0
 
azadisaryevCommented:
> 500 : The value returned from the getmynomos function is not of type query

you had this from the start - i just copied and pasted your code and didn;t notice this:

just look at the code for that function. the query's name is Q_NOMOS, but the function returns QGetNomos variable...

change the query's NAME attribute to match what the function returns:
<cfquery name="QGetNomos " datasource="#request.dsn#">

Azadi
0
 
PanosAuthor Commented:
I'm blind!!!!
Ok it is working now
0
 
PanosAuthor Commented:
Thank you very much
I will check thhe other question now
regards
panos
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now