4 Replies Latest reply on Jul 9, 2007 7:35 PM by Shane Bryzak

    Seam + AJAX: Remote problem

    Gregory Nikle Apprentice

      Hello,
      I have problem with example HelloWorld method...
      I've implemented those example in my project, on my index.xhtml page it works fine, but when i try to use it or some other AJAX functions on pages in my /pages/ folder (/pages/Person.xhtml) AJAX it could't work..

      My Firefox browser throws me an error: "Seam is not defined"
      at line: Seam.Component.getInstance("helloAction").sayHello(name, sayHelloCallback);

      Can anyone tell me why this works on my main page, and could't in other pages?
      I have acces to those pages after I log in to my web page, and when User is looged In i start LongRunningConversation (id=2).

      I have implemented all same as in Seam documentation.



      <script type="text/javascript" src="seam/remoting/resource/remote.js"> </script>
      <script type="text/javascript" src="seam/remoting/interface.js?userAction"></script>


      <script type="text/javascript">
      function sayHello() {
      var name = prompt("What is your name?");
      Seam.Component.getInstance("userAction").sayHello(name, sayHelloCallback);
      }

      function sayHelloCallback(result) {
      alert(result);
      }
      </script>

      etc.

      Regards!

        • 1. Re: Seam + AJAX: Remote problem
          Gregory Nikle Apprentice

           

          "sherkan777" wrote:
          Hello,
          I have problem with example HelloWorld method...
          I've implemented those example in my project, on my index.xhtml page it works fine, but when i try to use it or some other AJAX functions on pages in my /pages/ folder (/pages/Person.xhtml) AJAX it could't work..

          My Firefox browser throws me an error: "Seam is not defined"
          at line: Seam.Component.getInstance("helloAction").sayHello(name, sayHelloCallback);

          Can anyone tell me why this works on my main page, and could't in other pages?
          I have acces to those pages after I log in to my web page, and when User is looged In i start LongRunningConversation (id=2).

          I have implemented all same as in Seam documentation.



          <script type="text/javascript" src="seam/remoting/resource/remote.js"> </script>
          <script type="text/javascript" src="seam/remoting/interface.js?userAction"></script>


          <script type="text/javascript">
          function sayHello() {
          var name = prompt("What is your name?");
          Seam.Component.getInstance("userAction").sayHello(name, sayHelloCallback);
          }

          function sayHelloCallback(result) {
          alert(result);
          }
          </script>

          etc.

          Regards!


          • 2. Re: Seam + AJAX: Remote problem
            Gavin King Master

            You obviously have not got remote.js available in your page

            • 3. Re: Seam + AJAX: Remote problem
              Ian Bailey Newbie

               

              "sherkan777" wrote:

              My Firefox browser throws me an error: "Seam is not defined"
              at line: Seam.Component.getInstance("helloAction").sayHello(name, sayHelloCallback);


              I got this same problem, here was the problem I was having when I was using remoting on a view in a subdirectory of WebContent (say "subdir").

              The documentation (http://docs.jboss.com/seam/latest/reference/en/html/remoting.html#d0e9752 )says to include javascript libraries like so:

              <script type="text/javascript" src="seam/resource/remoting/resource/remote.js"></script>
              <script type="text/javascript" src="seam/resource/remoting/interface.js?customerAction"></script>
              


              However, the seam resource servlet is mapped at the root of the application:

              <servlet-mapping>
               <servlet-name>Seam Resource Servlet</servlet-name>
               <url-pattern>/seam/resource/*</url-pattern>
              </servlet-mapping>
              


              So my javascript includes were looking for files like:

              http://hostname/context/subdir/seam/remoting/interface.js

              When I should be looking in:

              http://hostname/context/seam/remoting/interface.js

              So I just changed my script tags in my views to this:
              <script type="text/javascript" src="../seam/resource/remoting/resource/remote.js"></script>
              <script type="text/javascript" src="../seam/resource/remoting/interface.js?customerAction"></script>
              


              You might have to adapt this depending on the structure inside your web directory, but that's the basic idea.

              • 4. Re: Seam + AJAX: Remote problem
                Shane Bryzak Master

                Seam 2.0 has a new tag, s:remote that generates the &lt;script&gt; tags automatically for you, with the correct path. Usage can be seen in the helloworld example (CVS) and looks like this:

                <s:remote include="customerAction"/>