0 Replies Latest reply on Mar 18, 2012 12:11 PM by jonathan.man

    Can't make ajax tags work properly on autocomplete/calendar

    jonathan.man Newbie

      Hi everyone.


      I'm having trouble making ajax work with richfaces component.


      I played with autocomplete and calendar, and my results are :


      Both component :

      - Change event : call to listener and rendering both ok


      - Autocomplete :

          blur : listener never called, render done only with a4j:ajax tag, but not with f:ajax

          selectitem : same as blur


      - Calendar :

          inputblur : listener never called, render never done even with a4j:ajax

          dateselect : same as inputblur


      I search the net for similar problems, but ended up on Jiras marked as resolved with richfaces 4.0 or 4.1.


      My setup :

      Eclipse indigo 3.7.2

      Tomcat 7.0.25


      Mojarra 2.1.7

      Richfaces 4.2.0


      This is my setup at home, but i encountered similar problems at work with a different setup.

      My setup at work is jdk1.6 and Indigo 3.7.0.

      In fact, my problems at work were the reason i tried it at home with a different setup.

      I even built an entire app with many test cases (f:ajax tag, a4j tag, different events...)



      Here is one of these test case. Events tested are blur (autocomplete) and inputblur (calendar), both with f:ajax tag.

      For autocomplete, using a4j:ajax would make the rendering work, but still not the listener.

      <rich:panel header="Autocomplete Test">
      <h:panelGrid columns="2">
      <h:outputText value="Chose value : " />
      <rich:autocomplete value="#{autocompleteTestBean.value}" 
      <f:ajax event="blur" listener="#{autocompleteTestBean.onEventTested}" render="autoSelectedValue autoNumCall messages" />
      <h:outputText value="Chosen value : " />
      <h:outputText id="autoSelectedValue" value="#{autocompleteTestBean.value}" />
      <h:outputText value="Number of calls to listener : " />
      <h:outputText id="autoNumCall" value="#{autocompleteTestBean.count}" />
      <rich:panel header="Calendar Test">
      <h:panelGrid columns="2">
      <h:outputText value="Chose value : " />
      <rich:calendar value="#{calendarTestBean.value}"
      <f:ajax event="inputblur" listener="#{calendarTestBean.onEventTested}" render="calSelectedValue calNumCall messages" />
      <h:outputText value="Chosen value : " />
      <h:outputText id="calSelectedValue" value="#{calendarTestBean.value}" />
      <h:outputText value="Number of calls to listener : " />
      <h:outputText id="calNumCall" value="#{calendarTestBean.count}" />
      <h:messages id="messages"/>


      The change event works fine for both.



      Here is my basic bean, since code is similar for both component :


      package fr.testcomp;
      import java.io.Serializable; 
      import javax.faces.event.AjaxBehaviorEvent;
      import org.richfaces.event.ItemChangeEvent;
      public class BaseTestComp implements Serializable {
          private static final long serialVersionUID = -408484402711572130L;
          private int count = 0;
          private Object value = null;
          public void onEventTested() {
              this.doCall("void do()");
          public void onEventTested(AjaxBehaviorEvent event) {
              this.doCall("void do(javax.faces.event.AjaxBehaviorEvent event)");
          public void onEventTested(ItemChangeEvent event) {
              this.doCall("void do(org.richfaces.event.ItemChangeEvent event)");
          private void doCall(String pSignature) {
              System.out.println("Listener call - Signature : " + pSignature);
              System.out.println("Listener call - Class : " + this.getClass());
              System.out.println("Listener call - Value : " + this.value);
         //getters and setters



      Both my managed beans inherits this one, with @ManagedBeans and @ViewScope annotations.

      The autocomplete one adds a random list of value :


      package fr.testcomp.autocomplete;
      import java.util.ArrayList;
      import java.util.List;
      import javax.faces.bean.ManagedBean;
      import javax.faces.bean.ViewScoped;
      import fr.testcomp.BaseTestComp;
      public class AutocompleteTestBean extends BaseTestComp {
          private static final long serialVersionUID = 5379541731429097364L;
          private List<String> values = null;
          public AutocompleteTestBean() {
              //init the list with some values
       //getter and setter


      The calendar bean extends BaseTestComp without adding anything.


      Here my dependancies.


              <!-- <slf4j.version>1.6.4</slf4j.version> -->


      Here is web.xml


      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
          <display-name>Test components</display-name>
              <servlet-name>Faces Servlet</servlet-name>
              <servlet-name>Faces Servlet</servlet-name>


      faces-context.xml is empty.


      I probably could make it work with a jsFunction, but I have that feeling that I must be missing something.

      And i'm afraid i'll encounter that behaviour on other components as well.

      Maybe I misunderstand the ajax tags?


      Sorry for the long post, it doesn't look like it, but i tried to make it short.