8 Replies Latest reply on Jun 25, 2008 4:28 AM by Kristen McGregor

    SuggestionBox commandLink not working

    Kristen McGregor Newbie

      Hi all! I am using the SuggestionBox component. Upon clicking the commandLink in the code below, the form submits, but the actionListener is not called. Any suggestions?
      Thanks!
      -Kris

      <rich:suggestionbox id="suggestionBoxId" for="searchBox"
       suggestionAction="#{bean.getResults}"
       var="result" minChars="2" border="1"
       width="250" height="150" cellpadding="2"
       nothingLabel="No search results found">
       <h:column>
       <h:commandLink actionListener="#{bean.selectValue}"
       value="#{result.name}">
       <f:attribute name="parameter" value="#{result.resultValue}" />
       </h:commandLink>
       </h:column>
       </rich:suggestionbox>


        • 1. Re: SuggestionBox commandLink not working
          Kristen McGregor Newbie

          p.s. I'm using RichFaces 3.2.1 and Sun RI 1.2_08

          • 2. Re: SuggestionBox commandLink not working
            Ilya Shaikovsky Master

            1) do not use 1.2_08 JSF version. There is a bug with encoding which stoper for some our components.

            2) in order to check your case - place rich:messages to your page. And use a4j:htmlCommandLink and a4j:form instead of h: ones.

            • 3. Re: SuggestionBox commandLink not working
              Kristen McGregor Newbie

              Thanks for the quick reply!

              I switched to JSF 1.2 and the a4j:form and a4j:htmlCommandLink, and unfortunately, the actionlistener is still not called. Any other suggestions? Do you know if there is an example app with this use case?

              Thanks!
              -Kris

              • 4. Re: SuggestionBox commandLink not working
                Phil Wilson Apprentice

                I have had a similar issue.

                Check out this messages stream.

                Menu issue with IE not in FireFox

                http://jboss.com/index.html?module=bb&op=viewtopic&t=137105&postdays=0&postorder=asc&start=0


                or this one.

                Problems with a4j:commandLink, paging forwarding and IE7

                http://jboss.com/index.html?module=bb&op=viewtopic&t=137495&start=10


                Both have issues with Commandlink.

                Phil

                • 5. Re: SuggestionBox commandLink not working
                  Kristen McGregor Newbie

                  Thanks for the links! Unfortunately, the actionListener (or action property, I've tried both) are not being called when in the suggestionbox on either Firefox or IE...

                  • 6. Re: SuggestionBox commandLink not working
                    Ilya Shaikovsky Master

                    krismcg, you tried using rich:messages or phasetracker in order to check lifecycle phases execution?

                    • 7. Re: SuggestionBox commandLink not working
                      Kristen McGregor Newbie

                      I wasn't able to retrieve any info from rich:messages, and I did not try the phasetracker. For some reason, it was not registering the command link's acitonListener. I did, however, get it to work with the following:

                      <script>
                       // Variable used to disable the enter key when the user selects an item
                       // from the suggestion box via the enter key.
                       var enterKeyEnabled = true;
                       function disableEnterKey() {
                       enterKeyEnabled = false;
                       }
                       function enableEnterKey() {
                       enterKeyEnabled = true;
                       }
                       function trapEnter(e, id) {
                       var element = document.getElementById(id);
                       // IE
                       if (window.event && window.event.keyCode==13) {
                       window.event.returnValue=false;
                       window.event.cancel=true;
                       element.click();
                       return false;
                       }
                       // Mozilla
                       else if (e.charCode==13 || e.keyCode==13 || e.which==13) {
                       // This looks hackish, but we can't click the submit button if an item
                       // from the suggestion box was selected via the Enter Key.
                       if(enterKeyEnabled)
                       element.click();
                       disableEnterKey();
                       return false;
                       }
                       return true;
                       }
                       </script>
                      
                       <h:inputText id="searchBox" size="20"
                       onkeypress="return trapEnter(event, '#{searchBoxBean.buttonClientId}');"
                       value="#{searchBoxBean.currentSearchTerms}">
                       </h:inputText>
                       <rich:suggestionbox id="suggestionBoxId" for="searchBox"
                       suggestionAction="#{searchBoxBean.getSearchResults}"
                       var="result" minChars="2" border="1"
                       width="250" height="150" cellpadding="2"
                       nothingLabel="">
                       <a4j:support event="onselect" onsubmit="disableEnterKey();" actionListener="#{searchBoxBean.selectValue}"
                       reRender="form"><f:attribute value="#{result.contextPath}" name="contextPath"/>
                       </a4j:support>
                       <h:column>
                       <h:outputText value="#{result.name}" />
                       </h:column>
                       </rich:suggestionbox>


                      In case others were interested, I included the extra code for handling the "Enter" key.

                      Thanks for all the suggestions!
                      -Kris

                      • 8. Re: SuggestionBox commandLink not working
                        Kristen McGregor Newbie

                        Sorry... One typo with enter key.. use this instead.

                        <script>
                         // Variable used to disable the enter key when the user selects an item
                         // from the suggestion box via the enter key.
                         var enterKeyEnabled = true;
                         function disableEnterKey() {
                         enterKeyEnabled = false;
                         }
                         function enableEnterKey() {
                         enterKeyEnabled = true;
                         }
                         function trapEnter(e, id) {
                         var element = document.getElementById(id);
                         // IE
                         if (window.event && window.event.keyCode==13) {
                         window.event.returnValue=false;
                         window.event.cancel=true;
                         element.click();
                         return false;
                         }
                         // Mozilla
                         else if (e.charCode==13 || e.keyCode==13 || e.which==13) {
                         // This looks hackish, but we can't click the submit button if an item
                         // from the suggestion box was selected via the Enter Key.
                         if(enterKeyEnabled)
                         element.click();
                         enableEnterKey();
                         return false;
                         }
                         return true;
                         }
                         </script>
                        
                         <h:inputText id="searchBox" size="20"
                         onkeypress="return trapEnter(event, '#{searchBoxBean.buttonClientId}');"
                         value="#{searchBoxBean.currentSearchTerms}">
                         </h:inputText>
                         <rich:suggestionbox id="suggestionBoxId" for="searchBox"
                         suggestionAction="#{searchBoxBean.getSearchResults}"
                         var="result" minChars="2" border="1"
                         width="250" height="150" cellpadding="2"
                         nothingLabel="">
                         <a4j:support event="onselect" onsubmit="disableEnterKey();" actionListener="#{searchBoxBean.selectValue}"
                         reRender="form"><f:attribute value="#{result.contextPath}" name="contextPath"/>
                         </a4j:support>
                         <h:column>
                         <h:outputText value="#{result.name}" />
                         </h:column>
                         </rich:suggestionbox>