3 Replies Latest reply on Feb 2, 2007 8:39 AM by shane.bryzak

    sequence execution not followed in seam reemoting

      Hi,

      I was facing a lot of problem in implementation of pop-up in my application.

      Eveytime I would invoke a pop-up, the javascript part (written in onclick attribute) would get executed before the my listener method (written in action attribute).

      After reading Seam Remoting, I tried to call a listener method from javascript function and was able to do so in the first attempt.

      Now my code looks like this:

      
       <script type="text/javascript" src="seam/remoting/resource/remote.js">
       </script>
      
       <script type="text/javascript" src="seam/remoting/interface.js?searchListener">
       </script>
      
       <script type="text/javascript">
       function fun_openSearchWindow(){
       alert('in fun_openSearchWindow()');
       Seam.Component.getInstance("searchListener").resetPage(resetPageCallback);
      
       window.open('search.jsf','search','scrollbars,height=400,width=700');
       }
       </script>
      
      



      But my problem is that 'window.open' function gets executed first before my 'resetPage' method gets executed completely, defeating the whole purpose of remoting in my case.

      Is there any way to keep the sequence of execution ?

      Thanks in advance ...

      Suraj

        • 1. Re: sequence execution not followed in seam reemoting
          shane.bryzak

          Remoting calls are asynchronous. You need to put any code that you want synchronized into the callback method.

          • 2. Re: sequence execution not followed in seam reemoting

            Thanks for the reply.

            I tried to write a callback method but could not catch the return string.

            My listener method looks like :

            @WebRemote
            public String resetPage() {
             logger.info(helper.formatLogMessage("Resetting the page"));
            
             if(searchDrugtUI != null) {
             searchDrugtUI.setFamily("");
             searchDrugtUI.setNameTypAnt("");
             searchDrugtUI.setWhoCode("");
             drugPEList = null;
             }
            
             return "success";
            }
            


            Javascript looks like :
            function fun_resetPage() {
             alert('in fun_resetPage');
             Seam.Component.getInstance("searchListener").resetPage(resetPageCallback);
            }
            
            function resetPageCallback(result) {
             alert(result);
             if(result == 'success') { fun_openSearchWindow();
             }
            }
            
            function fun_openSearchWindow(){
             Seam.Remoting.setDebug(true);
            
             Seam.Component.getInstance("searchListener").resetPage();
             //alert('in fun_openSearchWindow()');
             window.open('search.jsf','search','scrollbars,height=400,width=700');
            }
            


            I have enabled debug mode and can see the "success" string in response packet. But control does not come to "resetPageCallback()" method.

            Is there any thing wrong with "....("searchListener").resetPage(resetPageCallback);" ???

            I am not sure if I can put optional parameter "resetPageCallback" in method call to "resetPage()" when I have no compulsary paratmeter to pass.

            Regards,

            Suraj

            • 3. Re: sequence execution not followed in seam reemoting
              shane.bryzak

              Hmm... it should work. Can you try putting your callback method before the code that references it? I.e:

              function resetPageCallback(result) {
               alert(result);
               if(result == 'success') {
               fun_openSearchWindow();
               }
              }
              
              function fun_resetPage() {
               alert('in fun_resetPage');
               Seam.Component.getInstance("searchListener").resetPage(resetPageCallback);
              }
              
              function fun_openSearchWindow(){
               Seam.Remoting.setDebug(true);
              
               Seam.Component.getInstance("searchListener").resetPage();
               //alert('in fun_openSearchWindow()');
               window.open('search.jsf','search','scrollbars,height=400,width=700');
              }