-
1. Re: Seam Remoting - Getting values!
shane.bryzak Jan 31, 2010 10:33 PM (in response to notify)The A in AJAX stands for asynchronous. You need to define a callback method to receive the result of your invocation:
function loadDirectionsCallback(result) { alert('size = ' + result); } function loadDirections() { var devicesToTrackBean = Seam.Component.getInstance("devicesToTrackBean"); devicesToTrackBean.getPiNPOiNTsListSize(loadDirectionsCallback); }
-
2. Re: Seam Remoting - Getting values!
notify Jan 31, 2010 11:32 PM (in response to notify)Sorted. Many thanks.
-
3. Re: Seam Remoting - Getting values!
notify Feb 1, 2010 8:50 AM (in response to notify)Shane,
I am still having trouble getting a list of Objects back into an array. Whilst Googling I came across this post;
http://seamframework.org/Community/SeamRemotingAndEvaluatingELExpressions
Is this still the case? I'm using Seam 2.2.0.GA.
Thanks
-
4. Re: Seam Remoting - Getting values!
shane.bryzak Feb 1, 2010 8:55 AM (in response to notify)The eval feature is still disabled, but based on the code you pasted you're not using it anyway. What sort of trouble are you having exactly? It might help to post some code.
-
5. Re: Seam Remoting - Getting values!
notify Feb 1, 2010 11:04 AM (in response to notify)EJB passes back a list of DevicesToTrack entities;
@WebRemote
List getPiNPOiNTsList();
public List getPiNPOiNTsList() {
log.info("***** getPiNPOiNTsList pinPointsList = " + this.pinPointsList.size())
return this.pinPointsList;
}
The JavaScript Alert displays the size of the list/array correctly;
<script type="text/javascript">
function loadDirections() {
var devicesToTrackBean = Seam.Component.getInstance("devicesToTrackBean");
devicesToTrackBean.getPiNPOiNTsList(loadDirectionsCallback);
}
function loadDirectionsCallback(result) {
var piNPOiNTsList = result;
alert('loadDirections = ' + piNPOiNTsList.length);
}
</script>
However if I add a for loop in the JS to display the contents of the array;
function loadDirectionsCallback(result) {
var piNPOiNTsList = result;
alert('loadDirections = ' + piNPOiNTsList.length);
for (var i = 0; i < piNPOiNTsList.length; i++) {
alert("piNPOiNTsList: " + piNPOiNTsList[i]);
}
}
I get;
Error Parsing /map.xhtml: Error Traced[line: 39] The content of elements must consist of well-formed character data or markup.
Can't see for the life of me what's wrong with JS? -
6. Re: Seam Remoting - Getting values!
notify Feb 1, 2010 1:06 PM (in response to notify)¨Error Parsing /map.xhtml: Error Traced[line: 39] The content of elements must consist of well-formed character data or markup.¨
Solved - Replaced < with <
But unable to access the data from the array of entities. -
7. Re: Seam Remoting - Getting values!
shane.bryzak Feb 1, 2010 1:54 PM (in response to notify)Are you importing the JavaScript type stubs for the objects contained in the List? Also, why are you assigning the result param to a local variable? There's no need, just use the param directly.
-
8. Re: Seam Remoting - Getting values!
jgraul Feb 9, 2010 11:55 AM (in response to notify)I have exactly the same problem.
Has somebody found a solution by now? -
9. Re: Seam Remoting - Getting values!
notify Feb 9, 2010 12:12 PM (in response to notify)What is your problem?
I got it working by converting my List to an Array and passing that back to the JavaScript function.
<script language="JavaScript" type="text/javascript">
window.onload = initialize;
function initialize() {
var devicesToTrackBean = Seam.Component.getInstance("devicesToTrackBean");
devicesToTrackBean.getDevicesToTrackCurrentLocation();
loadDirections();
}
function loadDirections() {
var devicesToTrackBean = Seam.Component.getInstance("devicesToTrackBean");
devicesToTrackBean.getPiNPOiNTsListAsArray(loadDirectionsCallback);
}
function loadDirectionsCallback(piNPOiNTsList) {
var l = piNPOiNTsList.length;
var directions = new GDirections(NOTiFYPiNPOINTmap);
NOTiFYPiNPOINTmap.clearOverlays();
var directionsPanel;
var wayPoints = new Array(1);
var e = 0;
if (l > 1) {
for (var i = 0; i < l; i++) {
wayPoints[e] = new GLatLng(piNPOiNTsList[i][0], piNPOiNTsList[i][1]);
e++;
if ((((e % 25) == 0) && e != 0) || (e == l)) {
directions.loadFromWaypoints(wayPoints);
e = 0;
}
}
} else if (l == 1) {
var wayPoints = new Array(1);
wayPoints[0] = new GLatLng(piNPOiNTsList[0][0], piNPOiNTsList[0][1]);
var marker = new GMarker(wayPoints[0]);
NOTiFYPiNPOINTmap.addOverlay(marker);
}
}
</script>
In the Interface I have;
@WebRemote
String [][] getPiNPOiNTsListAsArray();
Works fine now! -
10. Re: Seam Remoting - Getting values!
jgraul Feb 11, 2010 7:42 AM (in response to notify)Thank you very much. It works for me too.