4 Replies Latest reply on Sep 17, 2015 9:48 AM by Y S

    Migrate rich:suggestionBox to rich:autocomplete problem

    Y S Newbie

      I use RF4.5.7 and I try to realize a migration from RF3 of a rich:suggestionBox.

       

      Based on solution found on this forum I have implemented a feature that update a div when an element is selected in rich:autocomplete.

      All this code is included by a <ui:include> inside another XHTML page.

       

      <rich:autocomplete id="stationId" minChars="3" var="station" inputClass="autoCompleteWidth300"  onselectitem="processSelectEvent(event.target);"
                         fetchValue="#{station.name}"
                         autocompleteMethod="#{controller.searchStations}"
                         mode="cachedAjax" required="true" autofill="false" layout="table">
      

      Below the code of the method processSelectEvent :

       

      function processSelectEvent(target) {
          alert(target.previousElementSibling.textContent);
          updateVal(target.previousElementSibling.textContent);
      }
      

      This method is fired because the alert is displayed.

       

      The updateVal method is a jsFunction

       

      <a4j:jsFunction 
          name="updateVal" 
          render="panelViewStation" 
          execute="@all" 
          onbegin="alert('begin');" 
          onbeforedomupdate="alert('onbeforedomupdate')" 
          oncomplete="alert('complete');"
          action="#{controller.aMethod}"  
          actionListener="#{controller.anotherMethod}"
          onerror="alert('error');">
              <a4j:param name="val" assignTo="#{controller.val}"/>
      </a4j:jsFunction>
      

       

      This method updateVal is called because "begin" (onbegin attribute) is displayed.

      But other attributes are not called (onbeforedomupdate, oncomplete, onerror) and the managed bean and assignTo are not called too (a4j:param, action, actionListener)

       

      The status of my investigations.

      - It seems that the autocompleteMethod send a partial response (in RF3, the rich:suggestionBox return the complete page) but on another part of the page

      - No error in the server console. No error in a4j:logs.

      - I put a phase tracker, and all the phases are realized (no error during validation phase)

       

      An help to resolve this problem (or to investigate) would be very appreciate.

       

      Thanks by advance

        • 1. Re: Migrate rich:suggestionBox to rich:autocomplete problem
          Michal Petrov Master

          I don't see a problem (other than target.previousElementSibling being null. There is a bug in 4.5.7 that makes the jsFunction execute twice, which is the opposite of your problem but you can still try updating to 4.5.9. If that doesn't work can you put together a reproducer?


          I don't understand the purpose of the function, you can save the string directly to the bean. Or you can use rich:select which can also work as autocomplete.


          • 2. Re: Migrate rich:suggestionBox to rich:autocomplete problem
            Y S Newbie

            I tried with the version 4.5.9 => no effect.

            I don't see a problem (other than target.previousElementSibling being null.

            The method updateVal is called because the "onbegin" alert is displayed.

             

            I don't understand the purpose of the function, you can save the string directly to the bean.

            I want to update a managed bean attribute on a "onselectitem" event. I found the solution in this post (https://developer.jboss.org/message/801870#801870).

             

            Or you can use rich:select which can also work as autocomplete.

            I try with rich:select, but it doesn't work too. Furthermore, I don't think I would be able to have such smart presentation (rich:column, ...) with a rich:select element.

             

            (to continue) my investigation :

            When I put a break point in the action and actionListener method (on server side), these methods are not called.

            I really think that I missed something during the migration...

            Have you a systematic method to find why a managed bean is not called by the client ?

             

            If that doesn't work can you put together a reproducer?

            It will be hard to reduce this situation to a short exemple, but I will try to make one.

            • 3. Re: Migrate rich:suggestionBox to rich:autocomplete problem
              Michal Petrov Master

              org.richfaces.renderkit.AjaxCommandRendererBase.dodDecode() should queue in an ActionEvent, after that javax.faces.UICommand.broadcast() will trigger both the actionListener and action. You can start there. One thing that would prevent the action from executing is if the jsFunction wasn't rendered but I don't assume that's the case.

              • 4. Re: Migrate rich:suggestionBox to rich:autocomplete problem
                Y S Newbie

                Thanks for your help.

                 

                I found a 1st problem

                the javax.faces.SEPARATOR_CHAR value was set to "_". I changed to "-" , now my managed bean is called.

                I saw in a forum that "_" character could make some trouble in the generating ID process.

                 

                But I'm still havng a problem with the jsFunction.

                 

                <a4j:jsFunction

                                name="updateVal"

                                onerror="alert('error')"

                                oncomplete="alert('end')"

                                render="panelViewStation">

                                    <a4j:param name="val" assignTo="#{searchController.searchStationController.stationId}"/>

                </a4j:jsFunction>

                 

                The "oncomplete" alert is now displayed, but the stationId is not assigned in the managed bean.

                 

                Thanks.