1 Reply Latest reply on Aug 19, 2006 2:59 AM by Shane Bryzak

    seam remoting - metadata array length

    Samual Roberts Newbie

      Hi,

      I have experienced an error using IE (5.5 and 6) with seam remoting.

      I believe I have a fix for the error, but was just wanting to check if anyone else has experienced it and whether my understanding is correct.

      The error message is 'field is null or not an object' and occurs in 'data += meta.field;' from seam/remoting/resource/remote.js :

      var meta = isComponent ? Seam.Component.getMetadata(obj) : Seam.Remoting.getMetadata(obj);
       for (var i = 0; i < meta.length; i++)
       {
       data += "<member name=\"";
       data += meta.field;
       data += "\">";
       data += Seam.Remoting.serializeValue(obj[meta.field], meta.type, refs);
       data += "</member>\n";
       }
      



      Here is the generated interface the error occurred on:

      Seam.Remoting.type.status.__name = "status";
      Seam.Remoting.type.status.__metadata = [
       {field: "code", type: "str"},
       {field: "disabled", type: "bool"},
       {field: "description", type: "str"},
       {field: "id", type: "number"},
       {field: "version", type: "number"},
      ];
      


      The generated interface code has a comma after the last field array value which makes IE treat the whole array as having length 6 (with an undefined element at the end) whereas firefox ignores the comma and treats the array as having a length of 5. IE iterates through all 5 valid fields, but then can't process the undefined 6th array element and fails.
      IE seems in this case to have the more correct javascript interpretation.


      To fix the issue, I made the following minor change to the org.jboss.seam.remoting.InterfaceGenerator class, rebuilt it and now it works fine on IE and Firefox.

       int i = 0;
       for (String key : metadata.keySet())
       {
       typeSource.append(" {field: \"");
       typeSource.append(key);
       typeSource.append("\", type: \"");
       typeSource.append(metadata.get(key));
       typeSource.append("\"}");
      
       // can't put ',' after last element of the generated array or javascript will interpret as undefined element
       if(i != metadata.keySet().size() -1){
       typeSource.append(",");
       }
       typeSource.append("\n");
      
       i++;
       }
      



      Happy to create a JIRA issue, but just wanted to check I was on the right track,

      Regards

      Samual