Question

In CF8, I have a working cftree with an RSS feed per node (multiple nodes). The problem is that I am not currently using a bind which means that all the feeds are read when the page is loaded which takes a very long time. What I want to do is bind the cftreeitem to a cfc so that the feed is only read when the user selects the parent cftreeitem and not on page load. The page is not throwing an error but none of the children nodes of the feed are showing under the parent.

cfm:
<cfform name="RSS_exercise">
<cftree name="Xfeeds" format="html" cache="no">
    <cftreeitem value="elite"  display="<div style='color:##4c4c4c'>ELITE FTS</div>" queryasroot="true" expand="no">
        <cftreeitem value="" bind="cfc:components.rssQ.getEliteRSS({cftreeitempath}, {cftreeitemvalue})">
</cftree>
</cfform>

cfc:
<cffunction name="getEliteRSS" access="remote" returntype="any" hint="gets EliteFTS RSS feed">
<cfargument name="itemPath" type="string" required="false"/>
<cfargument name="itemValue" type="string" required="false"/>
<cffeed source="http://feeds2.feedburner.com/EliteftsArticles" properties="eliteProps" query="eliteRSS">
<cfset var feedArray = ArrayNew(1) />
<cfset var feed = StructNew() />
<cfset var i = 1 />
<cfoutput query="eliteRSS">
    <cfset feed.value = "" />
    <cfset feed.display = "#title# <div style='color:gray'>Published: #DateFormat(publisheddate)#</div><br/>" />
    <cfset feed.href = "#rsslink#" />
    <cfset feed.target = "_blank" />
    <cfset feed.parent = "elite" />
    <cfset feed.queryAsRoot = "false" />
    <cfset feed.expand = "no" />
    <cfset feedArray[i] = Duplicate(feed) />
    <cfset var i = "i++" />
</cfoutput>
<cfreturn feedArray />
</cffunction>

Thank you very much for any help.


Made the following changes and now get the output, but it is nested/looped and I can't get the top level parent node so that they are not all flat. The point of doing this was so that there would be 1 parent that would not load the feed until checked.

cfm
<cfform name="RSS_exercise">
<cftree name="Xfeeds" format="html" cache="no">
    <cftreeitem bind="cfc:components.rssQ.getEliteRSS({cftreeitempath}, {cftreeitemvalue})">
</cftree>
</cfform>

cfc
<cffunction name="getEliteRSS" access="remote" returntype="array" output="no" hint="gets EliteFTS RSS feed">
<cfargument name="itemPath" type="string" required="false"/>
<cfargument name="itemValue" type="string" required="false"/>
<cfset var feedArray = ArrayNew(1) />
<cfset var feed = StructNew() />
<cfset var i = 1 />
<cffeed source="http://feeds2.feedburner.com/EliteftsArticles" properties="eliteProps" query="eliteRSS">
    <cfloop query="eliteRSS">
        <cfset StructClear(feed) />
        <cfset feed.value = "1" />
        <cfset feed.display = "#title# <div style='color:gray'>Published: #DateFormat(publisheddate)#</div><br/>" />
        <cfset feed.href = "#rsslink#" />
        <cfset feed.target = "_blank" />
        <cfset feed.parent = "elite" />
        <cfset feed.queryAsRoot = "false" />
        <cfset feed.expand = "no" />
        <cfset feedArray[i] = Duplicate(feed) />
        <cfset i++ />
    </cfloop>           
    <cfreturn feedArray />
</cffunction>
Was it helpful?

Solution 2

My first issue was not using the leafnode=true attribute for all the items within the feed. Then my next biggest issue was not properly setting the arguments.value so what was happening is that it was firing the cfc off every time a node was selected which just repeated the cffeed, again. Here is the cfc code that works as I had hoped:

<cffunction name="getEliteRSS" access="remote" returntype="array" output="no" hint="gets EliteFTS RSS feed">
    <cfargument name="path" required="true"/>
    <cfargument name="value" required="true"/>
    <cfset var feedArray = ArrayNew(1) />
    <cfset var feed = StructNew() />

    <cfif arguments.value IS "">
        <cfset feed.value = "elite" />
        <cfset feed.display = "<div style='color:##4c4c4c'>ELITE FTS</div>" />
        <cfset feed.leafnode = "false" />
        <cfset feed.expand = "no" />
        <cfset ArrayAppend(feedArray, feed) />
    <cfelse>
        <cffeed source="http://feeds2.feedburner.com/EliteftsArticles" properties="eliteProps" query="eliteRSS">
        <cfloop query="eliteRSS">
            <cfset feed = {} />
            <cfset feed.value = "" />
            <cfset feed.leafnode = "true" />
            <cfset feed.display = "#title# <div style='color:gray'>Published: #DateFormat(eliteRSS.publisheddate)#</div><br/>" />
            <cfset feed.href = "#rsslink#" />
            <cfset feed.target = "_blank" />
            <cfset feed.parent = "elite" />
            <cfset feed.queryAsRoot = "false" />
            <cfset ArrayAppend(feedArray, feed) />
        </cfloop>           
    </cfif>
    <cfreturn feedArray />
</cffunction>

OTHER TIPS

First of all you have to check two things:

  1. Make sure you return the JSON-encoded array (see manual).
  2. Install Firebug in your Firefox and track exact requests and responses using Console tab.

In the CFC you should use provided arguments to filter the data from feed. Maybe kind of QoQ on the fetched data.

Also few notes about your server-side code.

You don't have to use # everywhere, but you should use explicit scoping:

<cfset feed.href = "#rsslink#" />
<cfset feed.href = eliteRSS.rsslink />

You don't have to duplicate the structures and track the index. This can be much simpler:

<cfloop query="eliteRSS">
    <cfset feed = {} />
    ...
    <cfset ArrayAppend(feedArray, feed) />
</cfloop>  
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top