1 Reply Latest reply on May 2, 2011 7:07 AM by lfryc

    RichFaces4 autocomplete + many a4j:status

    edilmar

      Hi,

       

      Environment: NetBeans7 + GlassFish3.1 + JSF2 + RF4.0.0 final.

      I have many pages where there are many rich:autocomplete comps. For each comp, I use a "globe image" to warn the user that some process is doing at this moment. This worked fine in RF3.3.3, only the globe linked to suggestionBox was started when processing the search. However, with RF4.0.0, all the globes in the page are showed at the same time, and the user becomes crazy about what autocomplete is been processed. Below is the image for this sittuation:

      autocompleteManyStatus.jpeg

      This is the sample xhtml file, basically 4 autocomplete comps, each one with its a4j:status component:

       

      <a4j:region id="a4j_autocomplete">

        <rich:autocomplete id="cidade" mode="cachedAjax" minChars="2" showButton="true"

                           value="#{teste.cidade}" status="status_autocomplete"

                           autocompleteMethod="#{teste.autocomplete}"/>

        <a4j:status id="status_autocomplete" forceId="true">

          <f:facet name="start">

            <h:graphicImage  value="/imagens/processar.gif"/>

          </f:facet>

        </a4j:status>

      </a4j:region>

      <br/>

      <br/>

      <a4j:region id="a4j_autocomplete2">

        <rich:autocomplete id="cidade2" mode="cachedAjax" minChars="2" showButton="true"

                           value="#{teste.cidade2}" status="status_autocomplete2"

                           autocompleteMethod="#{teste.autocomplete}"/>

        <a4j:status id="status_autocomplete2" forceId="true">

          <f:facet name="start">

            <h:graphicImage  value="/imagens/processar.gif"/>

          </f:facet>

        </a4j:status>

      </a4j:region>

      <br/>

      <br/>

      <a4j:region id="a4j_autocomplete3">

        <rich:autocomplete id="cidade3" mode="cachedAjax" minChars="2" showButton="true"

                           value="#{teste.cidade3}" status="status_autocomplete3"

                           autocompleteMethod="#{teste.autocomplete}"/>

        <a4j:status id="status_autocomplete3" forceId="true">

          <f:facet name="start">

            <h:graphicImage  value="/imagens/processar.gif"/>

          </f:facet>

        </a4j:status>

      </a4j:region>

      <br/>

      <br/>

      <a4j:region id="a4j_autocomplete4">

        <rich:autocomplete id="cidade4" mode="cachedAjax" minChars="2" showButton="true"

                           value="#{teste.cidade4}" status="status_autocomplete4"

                           autocompleteMethod="#{teste.autocomplete}"/>

        <a4j:status id="status_autocomplete4" forceId="true">

          <f:facet name="start">

            <h:graphicImage  value="/imagens/processar.gif"/>

          </f:facet>

        </a4j:status>

      </a4j:region>

      And this is a simple bean:

       

      package control.testes;

       

      import java.io.Serializable;

      import java.sql.SQLException;

      import java.util.ArrayList;

      import java.util.List;

      import javax.enterprise.context.SessionScoped;

      import javax.inject.Named;

      import javax.persistence.EntityManager;

      import javax.persistence.PersistenceContext;

      import javax.persistence.Query;

       

      @Named

      @SessionScoped

      public class Teste implements Serializable {

        @PersistenceContext

        EntityManager emDAO;

        private String cidade;

        private String cidade2;

        private String cidade3;

        private String cidade4;

        public String getCidade() {return cidade;}

        public void setCidade(String cidade) {this.cidade = cidade;}

        public String getCidade2() {return cidade2;}

        public void setCidade2(String cidade2) {this.cidade2 = cidade2;}

        public String getCidade3() {return cidade3;}

        public void setCidade3(String cidade3) {this.cidade3 = cidade3;}

        public String getCidade4() {return cidade4;}

        public void setCidade4(String cidade4) {this.cidade4 = cidade4;}

        public List<String> autocomplete(String prefix) throws SQLException {

          List<String> result = new ArrayList<String>();

          System.out.println(prefix);

          if ((prefix == null) || (prefix.length() == 0)) {

            result.add("PREFIX VAZIO");

          } else {

            Query q = emDAO.createNativeQuery("select nome||'-'||codcidade from cidade where upper(nome) like '" + prefix.toUpperCase() + "%'");

            result = q.getResultList();

            if (result.isEmpty()) {

              result.add("NAO ACHOU NADA");

            }

          }

          return result;

        }

      }