7 Replies Latest reply on Jul 29, 2010 3:17 AM by ceene.ceene.gmx.net

    Ajax and Remoting

    ceene.ceene.gmx.net

      Hello community


      I have a project (My Project) and it runs without any problems.


      But if I change the location of the file where I'm use ajax the function on the Bean won't start. Where is the problem?


      I suggest the solution is simple but I don't get it.


      Sorry for the bad english :)

        • 1. Re: Ajax and Remoting
          ceene.ceene.gmx.net

          Please I need help.....it's urgent..... Nobody an idea?

          • 2. Re: Ajax and Remoting
            shane.bryzak

            Could you please explain the problem in more detail?  Code examples might help also.

            • 3. Re: Ajax and Remoting
              ceene.ceene.gmx.net

              I made the example from this page the only difference is that I made directories for the several site. One for the Java-Bean, one for the interface, one for the xhtml-site and one for the resources like the web-inf directory.


              my project directorie looks like: (Eclipse-Java-Project)




              -project
                 -src
                    -resources
                       -web-inf
                       -meta-inf
                    -src.ejb
                    -src.entity
                    -src.interfaces
                    -view
                    -view.pflege




              If the hello.xhtml-site is in the view directory the ajax-component do the job but if I put the hello.xhtml-site in the view.pflege directory the ajax do nothing. If I debug the ajax-component it looks like that the site can not find the bean or so. At least the javascript-variable for the bean is undefind.


              Click here for the code.


              What must I change that the hello.xhtml-site find the bean if the site is in the view.pflege directory?



              • 4. Re: Ajax and Remoting
                shane.bryzak

                Do you mean the bean stubs are undefined?  Or the return value when you invoke a server-side method?  I assume that you're trying to get the hello world example to work, however your source directory structure doesn't reflect the packaging structure so it's not really useful.  What would really help is if you provide the following things:


                1) The client code, both xhtml and javascript
                2) The structure and type of your deployment package
                3) A description of what actually happens as a result of putting your code in the view.pflege directory.  Does this get placed somewhere else in your deployment?

                • 5. Re: Ajax and Remoting
                  ceene.ceene.gmx.net

                  The bean stubs are undefiend.


                  Ok here my hello.xhtml:



                  
                  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                  <html xmlns="http://www.w3.org/1999/xhtml"
                         xmlns:ui="http://java.sun.com/jsf/facelets"
                         xmlns:h="http://java.sun.com/jsf/html"
                        xmlns:f="http://java.sun.com/jsf/core">
                  
                  <head>
                       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                  </head>
                  
                  <body>
                  
                  <script type="text/javascript" 
                    src="seam/resource/remoting/resource/remote.js">
                  </script>
                  
                  <script type="text/javascript" 
                    src="seam/resource/remoting/interface.js?manager">
                  </script>
                  
                  <script language="javascript">
                    // Seam.Remoting.setDebug(true);
                  
                    // don't display the loading indicator
                    Seam.Remoting.displayLoadingMessage = function() {};
                    Seam.Remoting.hideLoadingMessage = function() {};
                  
                    // Get the "manager" Seam component
                    var manager = 
                        Seam.Component.getInstance("manager");
                  
                    // Make the async call with a callback handler
                    function checkName () {
                      var e = document.getElementById("form:name");
                      var inputName = e.value;
                      manager.checkName(inputName, checkNameCallback);
                    }
                  
                    function checkNameCallback (result) {
                      if (result) {
                        hideCheckNameError ();
                      } else {
                        showCheckNameError ();
                      }
                    }
                  
                    function showCheckNameError () {
                      var e = document.getElementById("nameError");
                      if (!(e === null)) {
                        e.style.visibility = "inherit";
                        e.style.display = "";
                      }
                    }
                  
                    function hideCheckNameError () {
                      var e = document.getElementById("nameError");
                      if (!(e === null)) {
                        e.style.visibility = "hidden";
                        e.style.display = "none";
                      }
                    }
                    
                    function submitComment (newValue, oldValue) {
                      manager.setComment (newValue);
                    }
                  
                  </script>
                  
                  <h2>Demo der Dojo-Integration</h2>
                  
                  <h:form id="form">
                  
                  <table>
                  <tr>
                    <td>Ihr Name:</td>
                    <td>
                      <h:inputText id="name"
                                   value="#{person.name}"
                                   onfocus="hideCheckNameError()"
                                   onblur="checkName()"
                                   size="15"/>
                      <span id="nameError" style="display:none">Sie haben bereits »Hallo« gesagt!</span>
                      <h:message for="name" />
                    </td>
                  </tr>
                  <tr>
                    <td>Ihr Alter:</td>
                    <td>
                      <h:inputText id="age" value="#{person.age}"/>
                      <h:message for="age" />
                    </td>
                  </tr>
                  <tr>
                    <td>E-Mail:</td>
                    <td>
                      <h:inputText id="email" value="#{person.email}"/>
                      <h:message for="email" />
                    </td>
                  </tr>
                  <tr>
                    <td>Kommentar:</td>
                    <td>
                      <div id="comment" dojoType="inlineEditBox">Hallo Seam</div>
                    </td>
                  </tr>
                  </table>
                  </h:form>
                  
                  </body>
                  </html>
                  
                  



                  I deploy this project as an ear-file. If you open the ear-file it looks like


                   
                  - META-INF
                  - app.jar
                  - jboss-seam.jar
                  - app.war
                  


                  and the war-file looks like



                  - META-INF
                  - WEB-INF
                  - hello.xhtml
                  


                  If I deploy this everthing is fine. I see my page and if the name-textbox lost the focus everything is fine.


                  If I change the location of the hello.xhtml in my project to my view.pflege directory the ear-file the same as before and my war-file looks like



                  - META-INF
                  - WEB-INF
                  - pflege
                  



                  and in the pflege directory is the hello.xhtml-file. If I start my browser and get to the url (http://localhost:8080/remote/pflege/hello.xhtml) I see my page but nothings happens when the name-textbox lost the focus.


                  What can I do?

                  • 6. Re: Ajax and Remoting
                    shane.bryzak

                    If you move the hello.xhtml file you also need to update the path to the JavaScript resources, both for the remoting library and for the stub import. 


                    Change this:




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




                    To this:




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




                    • 7. Re: Ajax and Remoting
                      ceene.ceene.gmx.net

                      Thank you so much...... I can't belive it ....... two points and one slash .....


                      I searched in three books and so many pages in the web and nothing.


                      But now I'm realy happy.


                      Thanks again.