Solved

Coldfusion dependent-dropdown list error 500

Posted on 2009-03-31
13
452 Views
Last Modified: 2013-12-24
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
Comment
Question by:Panos
  • 6
  • 6
13 Comments
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24029825
> 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
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24029840
that's from the getmynomos cfc function, btw...

Azadi
0
 
LVL 2

Author Comment

by:Panos
ID: 24029886
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
 
LVL 2

Author Comment

by:Panos
ID: 24029964
getmynomos?
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24029969
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
 
LVL 2

Author Comment

by:Panos
ID: 24030533
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 13

Expert Comment

by:srikanthmadishetti
ID: 24032924
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
 
LVL 27

Accepted Solution

by:
azadisaryev earned 500 total points
ID: 24035317
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
 
LVL 27

Assisted Solution

by:azadisaryev
azadisaryev earned 500 total points
ID: 24035357
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
 
LVL 2

Author Comment

by:Panos
ID: 24037419
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
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24037489
> 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
 
LVL 2

Author Comment

by:Panos
ID: 24037840
I'm blind!!!!
Ok it is working now
0
 
LVL 2

Author Closing Comment

by:Panos
ID: 31564867
Thank you very much
I will check thhe other question now
regards
panos
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now