10 Replies Latest reply on Jun 15, 2011 1:15 PM by ibstmt

    jsFunction oncomplete parameters to the called function

    magiccreative

      hi,

      Is it possible to call jsFunction with parameters and then assign these parameters to another javascript function in the oncomplete event.

      For example there is a link:

       <input type='button' value='Link' onclick='someJsFunction('theParam')' />
      


      and a jsFunction

       <a4j:jsFunction name="someJsFunction" oncomplete="alert('hereIwantToSeeTheParam')">
      


      so basically I want to pass the javascript param further to the oncomplete 'someJsFunction'. I have seen how I can do this with a backing bean, but I would prefer not to have the additional requests. Any ideas?

        • 1. Re: jsFunction oncomplete parameters to the called function
          ilya_shaikovsky

          for sure.. it designed to work in this way.

          1) Use f:param's nested to jsFunction in order to pass parameters on firing request. Passed parameters will be put in request under defined names in corresponding order.

          2) use data attribute to serialize some data to client size with responce and then pass them to oncomplete.

          • 2. Re: jsFunction oncomplete parameters to the called function
            magiccreative

            thanks will give it a try

            • 3. Re: jsFunction oncomplete parameters to the called function
              magiccreative

              could't make it work

              Here is the call:

              <input type='button' value='Test' onclick='ajj("TheParam")' /><br />
              


              and here is the jsFunction:

               <a4j:jsFunction data="param1" name="ajj" oncomplete="alert(data)">
               <f:param name="param1" > </f:param>
              
               </a4j:jsFunction>
              


              1)Where do I set that param1 is equal to the first parameter after ajj("TheParam"

              2)How do I connect the alert("Param" to the passed one from the ajj("TheParam")' call, i.e to "TheParam"


              • 4. Re: jsFunction oncomplete parameters to the called function
                ilya_shaikovsky

                 

                <input type='button' value='Test' onclick='ajj("TheParam", "the second")' /><br />
                 <a4j:jsFunction name="ajj" >
                 <f:param name="param1" > </f:param>
                 <f:param name="param2" > </f:param>
                 </a4j:jsFunction>
                


                them will be put in request corresponding to order. param1 in this case - first passed param and param2 - the second.

                 <a4j:jsFunction data="#{userBean}" name="ajj" oncomplete="alert(data.name, data.surname)">
                


                where userBean object contains name and surname fields.

                • 5. Re: jsFunction oncomplete parameters to the called function
                  ibstmt

                  Found this thread and I have a question. I can't get my menuItem to work the way I want. I'm trying to open up a browser window via a menu click. My backing bean can format the parameter for the window.open function -- but the method never gets called. Here are the main pieces. I'm sure I've midunderstood the technique.

                   

                  <ui:define name="additionalMenus">

                  <rich:menuItem submitMode="none" value="Open">
                       <a4j:support event="onclick" immediate="true"   
                       onclick="openUrl()"/>
                  </rich:menuItem>

                  </ui:define>

                   

                  <h:form>     
                  <a4j:jsFunction name="openUrl" data="#{myBean.url}" >
                           oncomplete="window.open(data)" />                           
                  </a4j:jsFunction>

                  (followed by unrelated panelGrids, etc.)

                  </h:form>

                   

                  In myBean:

                  public String getUrl() {

                       String url = "'http://www.amazon.com', 'popupWindow', 'dependent=yes, menubar=yes, toolbar=yes, scrollbars=yes'";

                       return url;

                  }

                  • 6. Re: jsFunction oncomplete parameters to the called function
                    nbelaevski

                    Hi,

                     

                    Please try the following:

                     

                    public Object getUrl() {

                         Object url = new String[]{"http://www.amazon.com", "popupWindow", "dependent=yes, menubar=yes, toolbar=yes, scrollbars=yes"};

                         return url;

                    }

                     

                    <a4j:jsFunction name="openUrl" data="#{myBean.url}" >
                             oncomplete="window.open.apply(null, data)" />

                    • 7. Re: jsFunction oncomplete parameters to the called function
                      ibstmt

                      No luck -- one problem is that the openUrl method in the bean never gets called.

                      • 8. Re: jsFunction oncomplete parameters to the called function
                        ilya_shaikovsky

                        please add phasetracker to your application and check it's output.

                        • 9. Re: jsFunction oncomplete parameters to the called function
                          ibstmt

                          I finally figured this out. The problem was in how the template for this project was designed. The template has the menus in one form, and then my page has the main content in another form. As soon as I redesigned this so that the menus and main content were in one form, then the menuItem properly called the function and opened up a new browser window.

                           

                          Also, I did need to use Nick's method of passing a string of parameters to the window.open function.

                          • 10. Re: jsFunction oncomplete parameters to the called function
                            ibstmt

                            Hi, I wanted to provide an update to this problem. As my last post noted, I was able to get this to work. However, I've just discovered that it doesn't work in IE8.  IE won't open another window. Nothing happens. Works fine in Firefox.

                             

                            I realize this isn't a RichFaces issue, but has anyone discovered that window.open isn't working properly in IE8?

                             

                            Browsers... I hate them... at least the ones made by a certain software company.