6 Replies Latest reply on Nov 5, 2013 10:09 AM by Juraj Húska

    a4j:jsFunction neither listener nor actionListener is called

    Ivan Larionov Newbie

      Hi everyone,

       

      I am migrating an application from Richfaces 3 to 4 and having problems with <a4j:jsFunction>. It does not seem to call any listeners. I have created a test project based on maven archetype and, however, the actionListener is called, the listener attribute is still seems to be ignored. In my actual program, neither of the listeners are called. Could anyone help me? Possibly someone could give some insight into the problem.

       

      The following snippets are related to my test app and in the case the actionListener is called, listener is not called. Again, in my actual application neither is called.

       

      <!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:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:a4j="http://richfaces.org/a4j"
          xmlns:rich="http://richfaces.org/rich">
      
      <body>
          <ui:composition template="/templates/template.xhtml">
      
              <ui:define name="title">RichFaces Sample</ui:define>
      
              <ui:define name="body">
              
                  <h:outputScript target="head">
                  function internalCallServer() {
                      console.log("calling server...");
                      callServer();
                  }
                  </h:outputScript>
      
                  <h:form prependId="true">
                      
                          <h:outputLabel value="Host:" for="host" />
                          <h:inputText id="host" value="#{richBean.host}" />
      
      
                          <h:outputLabel value="Port:" for="port" />
                          <h:inputText id="port" value="#{richBean.port}" />
      
                          <rich:autocomplete id="docServerList" mode="client"
                              autocompleteList="#{richBean.suggestions}"
                              value="#{richBean.docServer}" showButton="true" minChars="0"
                              autofill="true" onfocus="internalCallServer()" />
                          
                          <a4j:status startText="Loading list..." stopText="" />
                          
                          <a4j:jsFunction name="callServer" render="docServerList"
                              execute="@form" listener="#{richBean.listener}" actionListener="#{richBean.actionListener}"/>
                      
                  </h:form>
                  
              </ui:define>
          </ui:composition>
      </body>
      </html>
          </ui:composition>
      </body>
      </html>
      
      
      
      
      </ui:define>
      
      
      
          </ui:composition>
      </body>
      </html>
      
      
      

       

      The bean:

       

      package somepackage;
      
      import java.io.Serializable;
      import java.util.ArrayList;
      import java.util.List;
      
      import javax.annotation.PostConstruct;
      import javax.faces.bean.ManagedBean;
      import javax.faces.bean.RequestScoped;
      import javax.faces.event.ActionEvent;
      import javax.faces.event.AjaxBehaviorEvent;
      
      @RequestScoped
      @ManagedBean
      public class RichBean implements Serializable {
      
          private static final long serialVersionUID = -6239437588285327644L;
      
          private String name;
          private String host;
          private String port;
          private String docServer;
          
          private List<String> suggestions = new ArrayList<String>();
          {
              suggestions.add("Option 1");
              suggestions.add("Option 2");
              suggestions.add("Option 3");
          }
          
          public List<String> getSuggestions() {
              return suggestions;
          }
      
          @PostConstruct
          public void postContruct() {
              name = "Option 2";
          }
      
          public String getName() {
              return name;
          }
      
          public void setName(String name) {
              this.name = name;
          }
      
          public String getHost() {
              return host;
          }
      
          public void setHost(String host) {
              this.host = host;
          }
      
          public String getPort() {
              return port;
          }
      
          public void setPort(String port) {
              this.port = port;
          }
      
          public String getDocServer() {
              return docServer;
          }
      
          public void setDocServer(String docServer) {
              this.docServer = docServer;
          }
          
          public void listener(AjaxBehaviorEvent e) {
              updateDocServerList();
          }
          
          public void actionListener(ActionEvent e) {
              updateDocServerList();
          }
          
          public void updateDocServerList() {        
              suggestions.clear();
              suggestions.add(getHost() + ":" + getPort() + " 1");
              suggestions.add(getHost() + ":" + getPort() + " 2");
              suggestions.add(getHost() + ":" + getPort() + " 3");
          }
          
      }
      }
          
          public void actionListener(ActionEvent e) {
              updateDocServerList();
          }
          
          public void updateDocServerList() {        
              suggestions.clear();
              suggestions.add(getHost() + ":" + getPort() + " 1");
              suggestions.add(getHost() + ":" + getPort() + " 2");
              suggestions.add(getHost() + ":" + getPort() + " 3");
          }
          
      }