Skip to main content
April 17, 2009
Question

Passing a URL parameter to a CFC using Spry.Data.XMLDataSet()

  • April 17, 2009
  • 1 reply
  • 375 views

Hi,

I'm having trouble passing a URL parameter (quizid) to a query in a CF component:

new Spry.Data.XMLDataSet("questions.cfc?method=getQuestionsXML&quizid=2","/question s/question",{useCache: false});

Regardless of the value that is passed through the URL, the query always uses the default value in cfargument. If I remove "default" from  the cfargument tag, it doesn't work at all (obviously).

I don't encounter this problem when I use <cfinvoke> to call the component. It only seems to be an issue when working with spry xml data sets. I have posted this question to the Spry forum, but haven't had any nibbles.... perhaps it is a CF issue.

Any ideas why this isn't working? Thanks in advance ....

(See below for the code.)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="spryassets/xpath.js"></script>
<script type="text/javascript" src="spryassets/SpryData.js"></script>
<script type="text/javascript" src="spryassets/SpryNestedXMLDataSet.js"></script>
<script type="text/javascript" src="spryassets/SpryAccordion.js"></script>
<script type="text/javascript" src="spryassets/SpryUtils.js"></script>
<link href="css/SpryAccordion.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var questiondata = new Spry.Data.XMLDataSet("questions.cfc?method=getQuestionsXML&quizid=2","/question s/question",{useCache: false});
questiondata.setColumnType("questiontext","html");

var answerdata = new Spry.Data.NestedXMLDataSet(questiondata, "answers/answer");
answerdata.setColumnType("answer","html");

var matchingdata = new Spry.Data.NestedXMLDataSet(questiondata, "matchingquestions/matchingquestion");

</script>

QUESTIONS.CFC:

<cfcomponent output="false">

<cffunction name="getQuestions" returnType="query" access="remote" output="false">
<cfargument name="quizid" type="numeric" required="yes" default="1">
<cfset var q = "">
   
<cfoutput>
<cfquery name="q" datasource="pwrtemp">
select *
from answers, questions
    where answers.qid = questions.qid and
    quizid = #quizid# order by questions.questionnum
</cfquery>
</cfoutput>

<cfreturn q>
</cffunction>

<cffunction name="getQuestionsXML" returnType="xml" access="remote" output="false">
<cfset var q = getQuestions()>
<cfset var pxml = "">
<cfxml variable="pxml">
    <questions>
  <cfoutput query="q" group="qid">
  <question>
        <qid>#qid#</qid>
        <questionnum>#questionnum#</questionnum>
        <correctanswers>#correctanswers#</correctanswers>
        <questiontext>#XMLFormat(question)#</questiontext>
        <cfif #q.questiontype# EQ "matching">
        <cfquery name="m" datasource="pwrtemp">
   select *
   from matching
      where matching.qid = #q.qid#
  </cfquery>
        <matchingquestions><cfloop query="m"><matchingquestion matchingid="#matchid#">#match_question#</matchingquestion></cfloop></matchingqu estions>
        </cfif>
        <answers><cfoutput><answer answerid="#answerid#">#answer#</answer></cfoutput></answers>
        <questiontype>#questiontype#</questiontype>
  </question>
  </cfoutput>
</questions>
</cfxml>
<cfcontent type="text/xml">
   
<cfreturn pxml>

</cffunction>

</cfcomponent>

    This topic has been closed for replies.

    1 reply

    Inspiring
    April 22, 2009

    What result do you get when you enter the following into your browser:

    http://mylocalhost_IP/path/to/component/questions.cfc?method=getQuestionsXML&quizid=2 ?

    (Replace http://mylocalhost_IP/path/to/component/ with the correct path to your component)

    Are the results valid/well-formed XML?  Is there any extraneous text that might interferre with the XML processing?  I noticed your xPath was looking for an element called "question s" - Is that the correct name of the element in your XML?  Is there really a space in the name?

    See if you can troubleshoot the issue using your browser first before adding it back into the Spry call.

    Hope that helps!

    - Michael