7 Replies Latest reply on Jan 6, 2010 9:18 PM by Tamas Malatinszki

    modify seam component from javascript

    István Gere Newbie

      Hy!


      I'm beginner in seam, and I don't know how to send parameters to my seam component from javascript.


      Here is the javascript code, I've got the lat and lng coordinates


      <script type="text/javascript">
           function get(latlng){
                map.panTo(marker.getPoint());
                var la = latlng.lat();
                var ln = latlng.lng();
                alert("Lat: " + la + ", Lng: " + ln);
           }
      </script>
      



      and my entity bean:


      @Entity
      @Scope(ScopeType.SESSION)
      @Name("site")
      public class Site {
      ...
      private double lat;
      private double lng;
      
      ... //getters and setters
      }
      



      So I'd like to transfer la coordinate to site.lat and ln to site.lng.
      Thanks in advance!


      I'm sorry if I didn't write correctly.(I'm Hungarian, and I'm not too good in English)

        • 1. Re: modify seam component from javascript
          Ilya Dyoshin Novice

          read documentation on Remoting :)  there is a great info on doing this.


          Best regards,
          Ilya Dyoshin

          • 2. Re: modify seam component from javascript
            Tamas Malatinszki Newbie

            Hi István,


            You can find a cool tutorial about remoting here. First You need to set up remoting in components.xml, then You need to put @WebRemote annotation on setLat and setLng functions, and then:


            <script type="text/javascript">
              function updateVariables() {
            
              //Your previous code
            
              Seam.Component.getInstance("site").setLat(la);
              Seam.Component.getInstance("site").setLng(ln);
            }
            </script>



            Regards,


            Tamás

            • 3. Re: modify seam component from javascript
              Tamas Malatinszki Newbie

              Some details more: put these lines into components.xml:


              <components xmlns:remoting="http://jboss.com/products/seam/remoting"
                          xsi:schemaLocation="http://jboss.com/products/seam/remoting http://jboss.com/products/seam/remoting-2.1.xsd">
              
              <remoting:remoting debug="true"/>



              Then modify the bean this way:


              import org.jboss.seam.annotations.remoting.WebRemote;
              
              @Entity
              @Scope(ScopeType.SESSION)
              @Name("site")
              public class Site {
              ...
              private double lat;
              private double lng;
              
                @WebRemote
                public void setLat(double lat){
                  this.lat=lat;
                }
              
                @WebRemote
                public void setLng(double lng){
                  this.lng=lng;
                }
              
              }



              And in the xhtml:


              <s:remote include="site"/>
              
              <script type="text/javascript">
                 function get(latlng){
                    map.panTo(marker.getPoint());
                    var la = latlng.lat();
                    var ln = latlng.lng();
                    Seam.Component.getInstance("site").setLat(la);
                    Seam.Component.getInstance("site").setLng(ln);
                    alert("Lat: " + la + ", Lng: " + ln);
                 }
              </script>



              Regards,


              Tamas


              • 4. Re: modify seam component from javascript
                István Gere Newbie

                Hi Tamás!


                I tried this way, before I opened this post. I saw this tutorial that is similar the seam reference tutorial. I tried to make the HelloWorld remoting example, but it didn't work. I've got a WARN message when I starting my JBoss server:
                [JAXWSDeployerHookPreJSE] Cannot load servlet class: org.jboss.seam.remoting.SeamRemotingServlet


                When I imported the jboss-seam-remoting.jar to my projekt, and I edited in Eclipse the web.xml, I've not find the SeamRemotingServlet class.


                <servlet>
                  <servlet-name>Seam Remoting</servlet-name>
                  <servlet-class>org.jboss.seam.remoting.SeamRemotingServlet</servlet-class>
                </servlet>
                



                I tried to find a jboss-seam-remoting.jar with this class, but I've not find. Do you think this is the source of trouble?

                • 5. Re: modify seam component from javascript
                  Tamas Malatinszki Newbie

                  Hmm...sounds weird, because my example is working fine in my test project without this servlet definition. My web.xml looks like this:


                   ... 
                    
                    <listener>
                      <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
                    </listener>
                  
                    <filter>
                      <filter-name>Seam Filter</filter-name>
                      <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
                    </filter>
                  
                    <filter-mapping>
                      <filter-name>Seam Filter</filter-name>
                      <url-pattern>/*</url-pattern>
                    </filter-mapping>
                  
                    <servlet>
                      <servlet-name>Seam Resource Servlet</servlet-name>
                      <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
                    </servlet>
                  
                    <servlet-mapping>
                      <servlet-name>Seam Resource Servlet</servlet-name>
                      <url-pattern>/seam/resource/*</url-pattern>
                    </servlet-mapping>
                  
                    ...



                  As far as I know Seam Resource Servlet should be enough for remoting, so You should try again with this configuration (see this topic, they had a similar issue with Seam Remoting).


                  Please let me know if it is working fine this way.


                  Regards,


                  Tamás

                  • 6. Re: modify seam component from javascript
                    István Gere Newbie

                    Hi Tamás!


                    Unfortunately, this isn't works in my case. I'd like to talk with you in Hungarian. If you registered in facebook, I found 1 result of your name, but I don't sure whehter you're (you play guitar in this picture).


                    Please write here if you're.

                    • 7. Re: modify seam component from javascript
                      Tamas Malatinszki Newbie

                      You're right, that's me. :)


                      Just drop a message on me, but after we find the root cause of this issue don't forget to post that here.