title: How to call a javascript function in jsf?
body: <p>I have an xhtml page and i want to call a javascript function in a4j:commandLink. I dont know why but the javascript method is not called. I have tried writing function into .js file using "ui:define", but still i am not able to call that method. Is this is something because it is not falling into the life cycle.</p>
  
  <p>The xhtml page is as follows: </p>
  
  <pre><code>&lt;ui:composition xmlns="http://www.w3.org/1999/xhtml"
  xmlns:rich="http://richfaces.org/rich"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:h="http://java.sun.com/jsf/html"&gt;
  
  &lt;h:head&gt;
  &lt;script type="text/javascript"&gt;
  function myFunction(){
      alert("Hello World!");
      }
  &lt;/script&gt;
  &lt;/h:head&gt;
  &lt;h:body&gt;
      &lt;h:panelGrid columns="2"&gt;
          &lt;h:outputText value="Choose the produce type:" /&gt;
          &lt;rich:inplaceSelect value="#{selectedBean.currentType}"
              valueChangeListener="#{selectedBean.valueChanged}"
              defaultLabel="Click here to select"&gt;
              &lt;f:selectItems value="#{selectedBean.firstList}" /&gt;
              &lt;a4j:ajax  event="change" reRender="items, label"
                  ajaxSingle="true"  oncomplete="myFunction()"/&gt;
                  &lt;a4j:log&gt;&lt;/a4j:log&gt;
          &lt;/rich:inplaceSelect&gt;
          &lt;a4j:outputPanel id="label"&gt;
              &lt;h:outputText value="Choose concrete product:"
                  rendered="#{not empty selectedBean.secondList}" /&gt;
          &lt;/a4j:outputPanel&gt;
          &lt;a4j:outputPanel id="items"&gt;
              &lt;rich:inplaceSelect value="#{selectedBean.currentItem}"
                  rendered="#{not empty selectedBean.secondList}"
                  defaultLabel="Click here to select"&gt;
                  &lt;f:selectItems value="#{selectedBean.secondList}" /&gt;
              &lt;/rich:inplaceSelect&gt;
          &lt;/a4j:outputPanel&gt;
      &lt;/h:panelGrid&gt;
  
  &lt;/h:body&gt;
  </code></pre>
  
  <p></p>