1 2 Previous Next 18 Replies Latest reply on Aug 5, 2006 5:47 AM by Richard Leherpeur

    @WebRemote: problem with client site instantiation of object

    Richard Leherpeur Novice

      Hello,

      I use a remoting method define as following:

      @WebRemote
      public List<SelectItem> getMyList(String id);
      

      On the client side, I get back a array of Object of the right size,
      but all the object are empty. It seam that the javascript client didn't
      know how to implement the SelectItem object.

      There is a post I think that is related to this similar issue:
      http://www.jboss.com/index.html?module=bb&op=viewtopic&t=83273

      Anything new on this?

      Thanks,

      Richard

        • 1. Re: @WebRemote: problem with client site instantiation of ob
          Shane Bryzak Master

          What Javascript do you have on the client?

          • 2. Re: @WebRemote: problem with client site instantiation of ob
            Richard Leherpeur Novice

            So I have the following javascript:

            <script type="text/javascript" src="/peanutcafe/seam/remoting/resource/remote.js">/* IE */</script>
            <script type="text/javascript" src="/peanutcafe/seam/remoting/interface.js?myManager">/* IE */</script>
            
            <script type="text/javascript">
            function getList(id){
             var myManager = Seam.Component.getInstance("myManager");
             var fctCallback = function(myList) {
             for (var idx = 0; idx < myList.length; idx++) {
             for(var field in myList[idx]) {
             alert(field + " : " + myList[idx][field]);
             }
             }
             myManager.getMyList(id, fctCallback );
            }
            </script>
            


            The list has been populated with the right number of object, but the javascript objects don't seems to be instantiated properly.

            Did I miss anything?


            • 3. Re: @WebRemote: problem with client site instantiation of ob
              Shane Bryzak Master

              Your javascript looks ok. Is SelectItem an interface? If it is, then there are still some outstanding issues with how remoting deals with interfaces.

              • 4. Re: @WebRemote: problem with client site instantiation of ob
                Richard Leherpeur Novice

                This is the javax.faces.model.SelectItem class that also implements java.io.Serializable

                • 5. Re: @WebRemote: problem with client site instantiation of ob
                  Shane Bryzak Master

                  What does /peanutcafe/seam/remoting/interface.js?myManager produce for the SelectItem class? Looking at the MyFaces implementation of SelectItem, it seems that they are using a non-standard naming convention for their javabean fields... ie. _value instead of just value. This might be what's messing up the stubs for this class.

                  • 6. Re: @WebRemote: problem with client site instantiation of ob
                    Richard Leherpeur Novice

                    This is what is generated:

                    Seam.Remoting.type.javax$faces$model$SelectItem = function() {
                    }
                    
                    Seam.Remoting.type.javax$faces$model$SelectItem.__name = "javax.faces.model.SelectItem";
                    Seam.Remoting.type.javax$faces$model$SelectItem.__metadata = [
                    ];
                    
                    Seam.Remoting.registerType(Seam.Remoting.type.javax$faces$model$SelectItem);
                    
                    


                    The field haven't been produced. As you said, that might just come from this strange naming convention they used.
                    I didn't think of checking the implementation of that javabean class!
                    I could just implement my own, but I'm not sure it is going to work properly with the selectOneMenu tag from the http://java.sun.com/jsf/html library.
                    Maybe we should ask the MyFaces team whether they could change this naming...
                    Thanks a lot for you help.

                    Richard

                    • 7. Re: @WebRemote: problem with client site instantiation of ob
                      Shane Bryzak Master

                      What you could do is implement your own javascript stub and register it with Seam.Remoting.registerType(), but it would be interesting to see what actual XML is being sent in response to your remoting call. You can enable debugging mode with Seam.Remoting.setDebug(true) which will show you the XML packets that are sent back and forth between the browser and the server. As far as I recall, the field values for the SelectItem object should still be sent back even if they don't have a matching getter/setter method.

                      • 8. Re: @WebRemote: problem with client site instantiation of ob
                        Richard Leherpeur Novice

                        Here are the XML packets:

                        Wed Aug 02 2006 14:56:54 GMT+0200 (Romance Daylight Time): Request packet:
                        <envelope>
                         <header>
                         <context><conversationId>10</conversationId></context>
                         </header>
                         <body>
                         <call component="myManager" method="getMyList" id="1">
                         <params>
                         <param>
                         <str>ID:12</str>
                         </param>
                         </params>
                         <refs></refs>
                         </call>
                         </body>
                        </envelope>
                        
                        
                        Wed Aug 02 2006 14:56:55 GMT+0200 (Romance Daylight Time): Response packet:
                        <envelope>
                         <header>
                         <context><conversationId>12</conversationId></context>
                         </header>
                         <body>
                         <result id="1">
                         <value>
                         <bag>
                         <element><ref id="0"/></element>
                         <element><ref id="1"/></element>
                         <element><ref id="2"/></element>
                         </bag>
                         </value>
                         <refs>
                         <ref id="0"><bean type="javax.faces.model.SelectItem"></bean></ref>
                         <ref id="1"><bean type="javax.faces.model.SelectItem"></bean></ref>
                         <ref id="2"><bean type="javax.faces.model.SelectItem"></bean></ref>
                         </refs>
                         </result>
                         </body>
                        </envelope>
                        


                        So if I write a stub for SelectItem and register it, Seam won't generate one and pick that one up. Is that what you mean?

                        • 9. Re: @WebRemote: problem with client site instantiation of ob
                          Richard Leherpeur Novice

                          So after registering myManager, I registered this classe:

                          Seam.Remoting.type.javax$faces$model$SelectItem = function() {
                           this._value = null;
                           this._label = null;
                           Seam.Remoting.type.javax$faces$model$SelectItem.prototype.getValue = function() { return this._value; }
                           Seam.Remoting.type.javax$faces$model$SelectItem.prototype.getLabel = function() { return this._label; }
                           Seam.Remoting.type.javax$faces$model$SelectItem.prototype.setValue = function(_value) { this._value = _value; }
                           Seam.Remoting.type.javax$faces$model$SelectItem.prototype.setLabel = function(_label) { this._label = _label; }
                          }
                          
                          Seam.Remoting.type.javax$faces$model$SelectItem.__name = "javax.faces.model.SelectItem";
                          Seam.Remoting.type.javax$faces$model$SelectItem.__metadata = [
                           {field: "_value", type: "str"},
                           {field: "_label", type: "str"},
                          ];
                          
                          
                          Seam.Remoting.registerType(Seam.Remoting.type.javax$faces$model$SelectItem);
                          


                          Looking at the javascript code, it should then replace the generated stub.

                          Then I tried again without success...

                          • 10. Re: @WebRemote: problem with client site instantiation of ob
                            Shane Bryzak Master

                             

                            "rlhr" wrote:


                            Wed Aug 02 2006 14:56:55 GMT+0200 (Romance Daylight Time): Response packet:
                            <envelope>
                             <header>
                             <context><conversationId>12</conversationId></context>
                             </header>
                             <body>
                             <result id="1">
                             <value>
                             <bag>
                             <element><ref id="0"/></element>
                             <element><ref id="1"/></element>
                             <element><ref id="2"/></element>
                             </bag>
                             </value>
                             <refs>
                             <ref id="0"><bean type="javax.faces.model.SelectItem"></bean></ref>
                             <ref id="1"><bean type="javax.faces.model.SelectItem"></bean></ref>
                             <ref id="2"><bean type="javax.faces.model.SelectItem"></bean></ref>
                             </refs>
                             </result>
                             </body>
                            </envelope>
                            


                            It looks like the field values for SelectItem aren't being serialized after all. I'll take a look at this today and see if I can come up with something that will work for the cases where the field naming doesn't match the getter/setter names.

                            • 12. Re: @WebRemote: problem with client site instantiation of ob
                              Shane Bryzak Master

                              I've checked in some changes to CVS which hopefully should fix your issue. It would be great if you could try this out for me and let me know if it works for you. One other neat thing that is now supported is explicit importing of non-component classes, so for example you can now import/browse this:

                              /seam/remoting/interface.js?javax.faces.model.SelectItem


                              to generate a client stub for the SelectItem class.

                              • 13. Re: @WebRemote: problem with client site instantiation of ob
                                Richard Leherpeur Novice

                                That's really cool.
                                I'm in the middle of something else right now and broke my app, but I still my be able to try your change today and give you some feedback.
                                Thanks a lot.

                                • 14. Re: @WebRemote: problem with client site instantiation of ob
                                  Richard Leherpeur Novice

                                  I finally got the opportunity to test the code you checked in.
                                  I downloaded jboss-seam-CVS.20060803.zip (which was created after your post).

                                  The interface created for the SelectItem class is:

                                  Seam.Remoting.type.javax$faces$model$SelectItem = function() {
                                   this.value = undefined;
                                   this.label = undefined;
                                   this.disabled = undefined;
                                   this.description = undefined;
                                  }
                                  
                                  Seam.Remoting.type.javax$faces$model$SelectItem.__name = "javax.faces.model.SelectItem";
                                  Seam.Remoting.type.javax$faces$model$SelectItem.__metadata = [
                                   {field: "value", type: "bean"},
                                   {field: "label", type: "str"},
                                   {field: "disabled", type: "bool"},
                                   {field: "description", type: "str"}];
                                  
                                  Seam.Remoting.registerType(Seam.Remoting.type.javax$faces$model$SelectItem);
                                  
                                  


                                  The xml received back from the server is:

                                  <envelope>
                                   <header>
                                   <context><conversationId>11</conversationId></context>
                                   </header>
                                   <body>
                                   <result id="1">
                                   <value>
                                   <bag>
                                   <element><ref id="0"/></element>
                                   <element><ref id="1"/></element>
                                   <element><ref id="2"/></element>
                                   </bag>
                                   </value>
                                   <refs>
                                   <ref id="0">
                                   <bean type="javax.faces.model.SelectItem">
                                   <member name="value"><number>-1</number></member>
                                   <member name="label"><str>AAAAAA</str></member>
                                   <member name="disabled"><bool>false</bool></member>
                                   <member name="description"><null/></member>
                                   </bean>
                                   </ref>
                                   <ref id="1">
                                   <bean type="javax.faces.model.SelectItem">
                                   <member name="value"><number>2</number></member>
                                   <member name="label"><str>BBBBB</str></member>
                                   <member name="disabled"><bool>false</bool></member>
                                   <member name="description"><null/></member>
                                   </bean>
                                   </ref>
                                   <ref id="2">
                                   <bean type="javax.faces.model.SelectItem">
                                   <member name="value"><number>3</number></member>
                                   <member name="label"><str>CCCCC</str></member>
                                   <member name="disabled"><bool>false</bool></member>
                                   <member name="description"><null/></member>
                                   </bean>
                                   </ref>
                                   </refs>
                                   </result>
                                   </body>
                                  </envelope>
                                  


                                  I was able to read the value fine using the properties "label" and "value".

                                  I noticed that the getters and setters are not generated for that bean.
                                  Is that in purpose?

                                  Anyway, that solve my problem. Awesome job!

                                  I didn't try the other functionnality you mentioned but actually I might also need it soon and therefore test it at the same time.

                                  Thanks

                                  1 2 Previous Next