4 Replies Latest reply on Mar 16, 2008 8:05 AM by shane.bryzak

    Sending WebRemote object back to server

    brombie.wanch.akewan.com

      Hi all,


      I'm wondering if you can create an entity from the browser side using Seam.component and pass it to server side.


      Here's what I have on the client side:



      <s:remote include="fruit,fruitAdmin"/> 
      var newFruit = Seam.Component.newInstance('fruit');
      newFruit.id='123';
      var fruitAdmin = Seam.Component.getInstance('fruitAdmin');
      fruitAdmin.save(newFruit);




      I've made sure that both Fruit and FruitAdmin have proper WebRemote annotations, but when the code above was executed, this is the error that I got:


      java.lang.RuntimeException: Error while unmarshalling - property [id] not found in class [test.Fruit]



      The reference doesn't have any mentions about marshalling a javascript object into its java entity counterpart.  Is this not supported yet?


      thanks!

        • 1. Re: Sending WebRemote object back to server
          shane.bryzak

          This should definitely work.  Could you please post the code for the fruit and fruitAdmin components?

          • 2. Re: Sending WebRemote object back to server
            brombie.wanch.akewan.com

            I figure out the original issue but got a new one.


            In my code, I had Fruit.java looking like this:



            package test;
            
            import org.jboss.seam.ScopeType;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.Scope;
            import org.jboss.seam.annotations.remoting.WebRemote;
            
            @Name("fruit")
            @Scope(ScopeType.EVENT)
            public class Fruit {
            
                 private long fruitId;
                 private String name;
                 
                 @WebRemote
                 public long getId() {
                      return fruitId;
                 }
                 @WebRemote
                 public void setId(long id) {
                      this.fruitId = id;
                 }
                 @WebRemote
                 public String getName() {
                      return name;
                 }
                 @WebRemote
                 public void setName(String name) {
                      this.name = name;
                 }
                 
            }



            It looks like Seam was looking for the member variable instead of the bean property through getter/setter.  So it found fruitId, instead of id.  


            I'm not getting the exception once I changed the fruitId to just id.  However, the value is not getting passed in.


            Here's the rest of the code pieces:


            FruitAdmin:


            package test;
            import javax.ejb.Local;
            import org.jboss.seam.annotations.remoting.WebRemote;
            @Local
            public interface FruitAdmin {
                 @WebRemote
                 public void save(Fruit fruit);
            }




            FruitAdminBean:


            package test;
            
            import javax.ejb.Stateless;
            
            import org.jboss.seam.annotations.Logger;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.log.Log;
            
            @Stateless
            @Name("fruitAdmin")
            public class FruitAdminBean implements FruitAdmin {
            
                 @Logger Log log;
                 
                 public void save(Fruit fruit) {
                      log.info("getting this fruit id: #0, name #1",fruit.getId(),fruit.getName());
                 }
            
            }
            



            and finally, the xhtml:


            <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                                         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            
            <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                            xmlns:s="http://jboss.com/products/seam/taglib"
                            xmlns:ui="http://java.sun.com/jsf/facelets"
                            xmlns:f="http://java.sun.com/jsf/core"
                            xmlns:h="http://java.sun.com/jsf/html"
                            xmlns:rich="http://richfaces.org/rich"
                            template="/layout/template.xhtml">
                                   
            <ui:define name="body">
                
            <s:remote include="fruitAdmin,fruit"/> 
            
            <script type="text/javascript">
            
            function createNewFruit() {
            
                 var fruitAdmin = Seam.Component.getInstance('fruitAdmin');
                 var newFruit = Seam.Component.newInstance('fruit');
                 newFruit.id=1234;
                 newFruit.name = "mango";
                 newFruit.justNumber = 56778;
                 newFruit.justString = "orange";
                 
                 fruitAdmin.save(newFruit);
                 
            }
            
            createNewFruit();
            
            </script>
            
            
            </ui:define>
            
            </ui:composition>
            


            • 3. Re: Sending WebRemote object back to server
              brombie.wanch.akewan.com

              Forgot to mention that when ran, the admin bean produces this output:



              INFO  [FruitAdminBean] getting this fruit id: 0, name mango




              I also tried changing from long to Long and got a null instead of 0.

              • 4. Re: Sending WebRemote object back to server
                shane.bryzak

                Could you post the request xml?  You can get this by turning on debug mode in remoting:


                Seam.Remoting.setDebug(true)



                It may also be useful to see the JavaScript stub that is being generated for the fruit component.  Just type the url that s:remote generates directly into your browser.


                Also you don't need all the @WebRemote annotations on the getter/setter methods in your bean, they are unnecessary.