Skip to main content

addRow not getting results

2 replies [Last post]
pmonday
Offline
Joined: 2006-05-15

I am trying to dynamically update a table using publish/subscribe. I put the following into my glue.js where users is returned as a JSONArray of a single user. The jMaki log shows an object reference and the table is not updated.

function returnUser(userid) {
jmaki.doAjax({method: "GET",
url: "UserLookup?userid=" + encodeURIComponent(userid),
callback : function(req) {
users = eval(req.responseText);
jmaki.publish("/table/ldapusertable/clear", { });
jmaki.publish("/table/ldapusertable/addRows",{value: users});
}
});
}
Publish : Topic: /table/ldapusertable/clear message {}
Publish : Topic: /table/ldapusertable/addRows message {value : [[object Object]]}

When I remove the {value: users} wrapper and the publish looks like this, the result is the JSONArray itself, but the table still does not update:
jmaki.publish("/table/ldapusertable/addRows",users);

Publish : Topic: /table/ldapusertable/addRows message [{lastname : 'Monday' , firstname : 'Paul' , userid : '1111' , email : 'Paul.Monday@Sun.COM'}]

Is there some subtle conversion I'm missing on this one? All of the examples seem to dodge using a variable and have hardcoded the {value: ...} results. Is there something simple I'm missing here like an object dereference of some kind (I tried toString on the object...no go).

Paul

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
pmonday
Offline
Joined: 2006-05-15

I think I fixed this, though its a bit puzzling. I changed the publish to go to /yahoo/dataTable and changed the subscribe on the widget to be symmetrical. It works now. I had assumed I could use my own event subscribe / publish pair but that completely didn't work. Now I'm curious how I would do two tables on the same page if I can't alter the publish / subscribe. This is the result:
function returnUser(userid) {
jmaki.doAjax({method: "GET",
url: "UserLookup?userid=" + encodeURIComponent(userid),
callback : function(req) {
users = eval(req.responseText);
jmaki.publish("/yahoo/dataTable/clear", { });
jmaki.publish("/yahoo/dataTable/addRows",{value: users});
}
});
}

And the widget is:
subscribe="['/yahoo/dataTable']"
service="UserLookup"

pmonday
Offline
Joined: 2006-05-15

This is continuing to haunt me. I am hoping someone has some insight. The examples I've found on the net seem to completely avoid the topic of two tables on a page ... unless they update them both simultaneously which is exactly what I am trying to get around! I have a feeling there is a definite bug here. I have modified one of my tables like this:

subscribe="['/adminView/lookupTable']"
service="UserLookup"/>

The second table looks like this:

subscribe="['/adminView/removeUserTable']"
publish="['/adminView/removeUserTablePublish']"
service="UserCollectionServlet" />

If I use this code in glue.js:
function returnAdminUser(myid) {
jmaki.doAjax({method: "GET",
url: "UserLookup?myid=" + encodeURIComponent(myid),
callback : function(req) {
users = eval('('+req.responseText+')');
jmaki.log("returnUser callback users="+users);
jmaki.publish("/adminView/lookupTable/clear", { });
jmaki.publish("/adminView/lookupTable/addRows",{value: users});

$('AddUserMessages').update(users[0].error);
}
});
}

The AddUserMessages is properly updated but the table is not. This exact same code works if I publish to /yahoo/dataTable and have only a single table on a page that subscribes to /yahoo/dataTable (see last message). So, I got a little curious and went into collab.js and changed the subscriber list to this:
var subscribe = ["/yahoo/dataTable", "/table", "/adminView/lookupTable"];

Now BOTH tables get cleared and the rows added.

Is there a known / unknown bug in the yahoo.dataTable with subscribing only to my own topic? Perhaps the table is initialized prior to changing the subscriber list? Perhaps two tables on a page cannot be handled independently because of some event handling code? I am still trying to debug but am not the most prolific javascript debugger on the planet.

Paul