8 Replies Latest reply on Dec 17, 2008 12:41 PM by Romain Cherchi

    rich:suggestionbox, ajax and pages.xml

    Romain Cherchi Newbie

      Hi guys,


      I'm using JBoss 4.2.3.GA and Seam 2.1.1.CR1.


      I have a problem with rich:suggestionbox calling the init method of its page Session Bean everytime I type a new letter :(


      Here is the configuration :



      • pages.xml




      <page view-id="/index.xhtml" action="#{indexManager.init}">
      ...
      </page>
      




      • index.xhtml



      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                          xmlns:ui="http://java.sun.com/jsf/facelets"
                          xmlns:h="http://java.sun.com/jsf/html"
                          xmlns:rich="http://richfaces.org/rich"
                          xmlns:fn="http://java.sun.com/jsp/jstl/functions">
           
           <rich:suggestionbox      
                              id="#{suggestionBoxId}"
                     for="#{inputTextId}" 
                     suggestionAction="#{globalServiceManager.autocompleteCtgDetails}"
                     var="suggestedCtg"
                        requestDelay="100"
                     ignoreDupResponses="true">
                                         
                <h:column id="#{suggestionBoxId}-col-#{suggestedCtg.id}">
                     <h:outputText id="#{suggestionBoxId}-output-#{suggestedCtg.id}" value="#{fn:toLowerCase(suggestedCtg.name)}"/>
                </h:column>
                
           </rich:suggestionbox>
           
      </ui:composition>




      • IndexManagerBean




      
      @Stateful
      @Scope(SESSION)
      @Name("indexManager")
      public class IndexManagerBean implements IndexManagerLocal, Serializable {
      
              private boolean isAjaxCall = false;
      
           public void init() {
                System.out.println("> init...");
                
                if (!isAjaxCall) {
                     System.out.println("> init !");
      
                              //
                              // Some code
                              //
                      }
              }
      
           /**
            * WebRemote call. In the case of a AJAX call. Block init method rewrite.
            */
           public void startAjaxCall() {
                System.out.println("Start >");
                isAjaxCall = true;
           }
      
           public void endAjaxCall() {
                System.out.println("< End");
                isAjaxCall = false;
           }
      }
      



      I use the isAjaxCall flag to prevent multiple init() code when an ajax request is fired. This is very ugly but it's the only way I found to fix it so far.
      It works with a4j but I didn't find a method like actionListener in richfaces :



      <a4j:outputPanel id="resultLstCtrl">
           <ui:include src="/include/pages/root/index/review-list-navigation-ajax.xhtml" />     
      </a4j:outputPanel>
      
      <a4j:form>
            <a4j:jsFunction name="refreshResultLstCtrl" 
                      reRender="resultLstCtrl"
                      actionListener="#{indexManager.startAjaxCall}"
                      requestDelay="100"
                  ignoreDupResponses="true"                                         oncomplete="index.refreshResultLstCtrlCallbackComplete();"/>
      </a4j:form>
      




      Is there a better way to fix this ?


        • 1. Re: rich:suggestionbox, ajax and pages.xml
          Chris Simons Expert

          Have you tried wrapping your suggestionBox inside of an a4j:region?


          What version of RichFaces are you using?

          • 2. Re: rich:suggestionbox, ajax and pages.xml
            Romain Cherchi Newbie

            Thanks but it doesn't change with a4j:region. I'm using the version of RichFaces shipped with Seam 2.1.1.CR1 (I don't know exactly what it is...)

            • 3. Re: rich:suggestionbox, ajax and pages.xml
              Romain Cherchi Newbie

              I also have this issue with seam remoting (via javascript calls).

              • 4. Re: rich:suggestionbox, ajax and pages.xml
                Ingo Jobling Master

                Hi, I'm not sure that I understand completely, but perhaps the message queue facility in A4J would be useful?

                • 5. Re: rich:suggestionbox, ajax and pages.xml
                  Romain Cherchi Newbie

                  The console output is :


                  19:17:05,905 INFO  [STDOUT] > init...
                  19:17:05,906 INFO  [STDOUT] > init !
                  19:17:12,394 INFO  [STDOUT] > init...
                  19:17:12,395 INFO  [STDOUT] > init !
                  19:17:14,118 INFO  [STDOUT] > init...
                  19:17:14,119 INFO  [STDOUT] > init !
                  19:19:20,819 INFO  [STDOUT] > init...
                  19:19:20,820 INFO  [STDOUT] > init !
                  19:19:21,364 INFO  [STDOUT] > init...
                  19:19:21,365 INFO  [STDOUT] > init !
                  19:19:21,860 INFO  [STDOUT] > init...
                  19:19:21,861 INFO  [STDOUT] > init !
                  19:19:22,774 INFO  [STDOUT] > init...
                  19:19:22,775 INFO  [STDOUT] > init !
                  19:19:23,177 INFO  [STDOUT] > init...
                  19:19:23,177 INFO  [STDOUT] > init !
                  19:19:23,625 INFO  [STDOUT] > init...
                  19:19:23,626 INFO  [STDOUT] > init !
                  19:19:25,593 INFO  [STDOUT] > init...
                  19:19:25,593 INFO  [STDOUT] > init !
                  19:19:26,083 INFO  [STDOUT] > init...
                  19:19:26,084 INFO  [STDOUT] > init !
                  19:19:26,565 INFO  [STDOUT] > init...
                  19:19:26,565 INFO  [STDOUT] > init !
                  19:19:31,821 INFO  [STDOUT] > init...
                  19:19:31,827 INFO  [STDOUT] > init !
                  19:20:07,320 INFO  [STDOUT] > init...
                  19:20:07,321 INFO  [STDOUT] > init !
                  19:20:23,557 INFO  [STDOUT] > init...
                  19:20:23,557 INFO  [STDOUT] > init !
                  19:20:24,070 INFO  [STDOUT] > init...
                  19:20:24,070 INFO  [STDOUT] > init !
                  19:20:24,461 INFO  [STDOUT] > init...
                  19:20:24,461 INFO  [STDOUT] > init !
                  19:20:29,745 INFO  [STDOUT] > init...
                  19:20:29,746 INFO  [STDOUT] > init !
                  19:20:30,369 INFO  [STDOUT] > init...
                  19:20:30,370 INFO  [STDOUT] > init !
                  19:20:59,555 INFO  [STDOUT] > init...
                  19:20:59,555 INFO  [STDOUT] > init !
                  19:22:47,716 INFO  [STDOUT] > init...
                  19:22:47,717 INFO  [STDOUT] > init !
                  19:23:04,085 INFO  [STDOUT] > init...
                  19:23:04,085 INFO  [STDOUT] > init !
                  19:23:04,612 INFO  [STDOUT] > init...
                  19:23:04,613 INFO  [STDOUT] > init !
                  19:23:04,973 INFO  [STDOUT] > init...
                  19:23:04,974 INFO  [STDOUT] > init !
                  19:23:05,354 INFO  [STDOUT] > init...
                  19:23:05,355 INFO  [STDOUT] > init !
                  19:23:05,771 INFO  [STDOUT] > init...
                  19:23:05,771 INFO  [STDOUT] > init !
                  19:24:18,290 INFO  [STDOUT] > init...
                  19:24:18,290 INFO  [STDOUT] > init !
                  19:24:25,903 INFO  [STDOUT] > init...
                  19:24:25,903 INFO  [STDOUT] > init !
                  19:24:27,044 INFO  [STDOUT] > init...
                  19:24:27,045 INFO  [STDOUT] > init !
                  19:24:27,428 INFO  [STDOUT] > init...
                  19:24:27,428 INFO  [STDOUT] > init !
                  19:24:32,689 INFO  [STDOUT] > init...
                  19:24:32,690 INFO  [STDOUT] > init !
                  




                  And the code (including database queries) in


                  //
                  // Some code
                  //
                  



                  gets executed each time a user presses a key in the rich:suggestionbox components.

                  • 6. Re: rich:suggestionbox, ajax and pages.xml
                    Nikolay Elenkov Master

                    Try something like:


                    <action if="#{empty param['javax.faces.ViewState']}"
                          execute="#{indexManager.init}" />
                    



                    There should be a new attribute for this in Seam 2.1, but I can't remember the name. Check the XSD.


                    • 7. Re: rich:suggestionbox, ajax and pages.xml
                      Stefano Travelli Newbie

                      The new attribute is named 'on-postback':



                      <action on-postback="false" execute="#{indexManager.init}"/>


                      • 8. Re: rich:suggestionbox, ajax and pages.xml
                        Romain Cherchi Newbie

                        Great ! Thank you guys... it's perfect now :-)