View Single Post
  #1 (permalink)  
Old December 10th, 2007, 01:11 PM
celticbhoy celticbhoy is offline
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help: Arrays using JavaScript,/JSP Iterator in IE

Thank you for looking at this problem!

I am having major problems with getting IE 6 and 7 trying to access XML generated from a Custom Object Array. If someone can sort this out for me il give them 10 Duke stars. This problem has been driving me crazy...

First il describe my application... Basically it should display items on a map. But before that I need it to access members of the Array in question....

Firstly I have an object called MappingDisplay....

Code:
public class MappingDisplay implements Serializable { 
private static final long serialVersionUID = -4293462259215498921L; 
private String _vehicleName; 
private double _latitude; 
private double _longitude; 
 
public MappingDisplay(String vehicleName, double latitude, double longitude) 
{ 
this._vehicleName = vehicleName; 
this._latitude= latitude; 
this._longitude= longitude; 
} 
 
public String getVehicleName() { 
return _vehicleName; 
} 
 
public double getLongitude() { 
return _longitude; 
} 
 
public double getLatitude() { 
return _latitude; 
}

Then in a Struts Action I create an Array of MappingDisplays and put them in the session...


Code:
// returns a List of MappingDisplay objects 
List mappingList = getMappingDisplayList(form); 
// creates and populates the Array that goes in the session 
 
MappingDisplay[] mappingArray = new MappingDisplay[mappingList.size()]; 
for (int i = 0; i < mappingList.size(); i++) { 
mappingArray[i] = (MappingDisplay) mappingList.get(i); 
} 
session.setAttribute("mappingArray", mappingArray);

The mappingArray definately gets populated properly because the JavaScript im using for FireFox gets the values correctly... I have also debugged the code and it is fine.

I am using Tiles to insert a JSP with an iterator to iterate through the objects in the Array in the session and create XML (stored on the server AFAICT ?)

itemOnMapIterator.jsp...

Code:
<div id="xmlData" style="display:none">
<c:forEach var="mappingDisplay" varStatus="current" items="${mappingArray}">
<c:if test="${current.last}">
<c:set var="numberOfVehicles" value="${current.count}"/>
</c:if>
<mappingDisplay>
<vehicleName><c:out value="${mappingDisplay.vehicleName}"/></vehicleName>
<latitude><c:out value="${mappingDisplay.latitude}"/></latitude>
<longitude><c:out value="${mappingDisplay.longitude}"/></longitude>
</mappingDisplay>
</c:forEach>
</div>

Then on a separate JSP I am trying to access the values of the XML created from the Array.

The code for Firefox works fine...

mapsFormLayout.jsp

Code:
function parseXmlContent()
{                                    
    var browserLabel="";
    // custom browser checker    
    if (BrowserDetect.browser == "Explorer") 
    {
        browserLabel="IE";
        alert("browser= " + browserLabel);
        getMappingData();
    }

    else
    {
        browserLabel="FireFox";
        alert("browser= " + browserLabel);

        var objectPosition = document.getElementById('xmlData').getElementsByTagName("mappingDisplay");
 
        alert("objectPosition - " + objectPosition.length);

         for(var i = 0; i < objectPosition.length ; i++)
               {
               var vehicleName = objectPosition[i].getElementsByTagName("vehicleName").item(0).firstChild.data;       
                    alert("vehicleName " + vehicleName); 
             }
        }
    }
When I load the page in FireFox the alert correctly gives me the name of the vehicle. However when I use the same code in IE I get many errors such as

"Error: Object required" or "Error: Object doesn’t support this property or method"

I have read here, and in other places that IE cannot access the Array notes by using
.item(0).firstChild.data etc

So I have tried to build the JavaScript method getMappingData(); above so that IE can access the elements on the Array... This is as far as I have gotten...


Code:
function getMappingData() 
    {
    // THIS IS PROBABLY WRONG
    var objectPosition = document.getElementById('xmlData').getElementsByTagName("mappingDisplay");

    var maxMaps = objectPosition.length;
    alert("maxMaps: " + maxMaps); // fires correctly

    // CODE NEEDED HERE
    }
When the page is loaded I am checking vehicle checkboxes and submitting the form and that puts the values in the MappingDisplay. I have debugged the Java and used the alerts on the FireFox JS code to read the values and it reads them all fine.

The alert above tells me the correct length of the Array but I cant access the members!
I have a feeling the I am not accessing the array properly in the IE JavaScript. It seems to recognise the length but doesn’t recognise it as an Array or cant seem to access its members.

All I want to do is put the correct vehicleName, longitude and latitude in an alert.

I have used various ways to get the JavaScript when browsing with IE 6/7 to read the values in the Array but to no avail...

I have been stuck at this one for quite a while!
Any help, and suggestions would be deeply appreciated!



Reply With Quote