I have a journal app where I have a fancytree showing the journal entries for the user logged in. Below that tree, I have another fancytree with a dropdown above it that lets you select other users and browse their journal entries. Once you select a user, it grabs their user ID, then loads the second tree with their entries. This works great until about the 7th selection, in which the tree hangs up and basically kills my Tomcat session. I have to restart Tomcat in order to fix it.
My HTML is:
<div class="journalList left-column">
<div id="logTree"></div>
<div class="browser">
<div class="userWrapper">
<h4>Browse Other User Logs</h4>
<select id="otherUser">
</select>
</div>
<div id="browseTree"></div>
</div>
</div>
The ID logTree is the fancytree for the user that is logged in. The browseTree is for the selected user.
Relevant code in JavaScript for #logTree.
$('#logTree').fancytree({
source: {
type: 'post',
cache: false,
url: "/LogbookServlet",
data: {action:"init", sub:"logtree"},
datatype: 'json'
},
lazyLoad: function(event, data) {
var node = data.node;
data.result = getLogTreeData(node.key);
},
loadChildren: function(event, data) {
var node = data.node;
var activeNode = $("#logTree").fancytree("getActiveNode");
if (activeNode) {
activeNode.setExpanded(true);
var mon = new Date().getMonth();
var curMonth = months[mon];
var children = activeNode.getChildren();
if (children) {
for (var i = 0; i < children.length; i++) {
var childNode = children[i];
var title = childNode.title;
if (title == curMonth) {
$("#logTree")
.fancytree("getTree")
.activateKey(childNode.key);
}
}
}
}
}
});
This section of code is called when the page is first loaded:
var otherUsrId;
$('#browseTree').fancytree({
source: [],
lazyLoad: function(event, data) {
var node = data.node;
data.result = getLogTreeData(node.key, otherUsrId);
},
loadChildren: function(event, data) {
var node = data.node;
}
});
I have a handler for the Select to detect the change of users:
$('#otherUser').on('change select', function() {
// Get the User ID from the Select
otherUsrId = $(this).val();
getUserTree(otherUsrId);
});
And here is the code for getUserTree():
function getUserTree(otherUsrId) {
var userTree = $('#browseTree').fancytree("getTree");
userTree.reload({
url: "/LogbookServlet",
data: {action:"init", sub:"logtree", otherUsrId:otherUsrId},
datatype: 'json'
});
}
So, after selecting a user for the 7th time, the "browseTree" fancytree just hangs with the loading icon spinning and it kills my browser. Any ideas? It appears that maybe something is getting called too recursively? Not sure.