2 Replies Latest reply on Feb 2, 2011 1:43 PM by Sergey Morenets

    Submit JavaScript value to a4j:commandLink

    Sergey Morenets Novice

      Hi

       

      I want to integrate star rating plugin into RichFaces. Here is the JavaScript code

       

       

                          <input name="star1" type="radio" class="star" value="1" />
                          <input name="star1" type="radio" class="star" value="2" />
                          <input name="star1" type="radio" class="star" value="3" />
                          <input name="star1" type="radio" class="star" value="4" />
                          <input name="star1" type="radio" class="star" value="5" />
                          <rich:jQuery selector="#input" query="rating();" />
      
      

       

      I want to sumbit the selected value to my backing bean using the following code

       

       

                          <a4j:commandLink 
                                  action="#{myBean.setRating(rich:component('star1').value)}"
                                  value="#{msg['rating']}">
                              </a4j:commandLink>                    
      

       

      However I always get empty string as a parameter value. I tried to change name="star1" with id="star1" but without success. Is there any trusted way to do that?

       

      Thanks.

        • 1. Submit JavaScript value to a4j:commandLink
          Ilya Sorokoumov Master

          Try to use a4j:actionparam

          http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/a4j_actionparam.html

          This link says:

          It is possible to use JavaScript expression or function in the "value" attribute. In this case the "noEscape" attribute should be set to "true". The result of this JavaScript invocation is sent to the server as a value of <a4j:actionparam> .
          • 2. Re: Submit JavaScript value to a4j:commandLink
            Sergey Morenets Novice

            Thanks, Ilya.

            It works

             

             

            <a4j:commandLink action="#{myController.vote(myBean)}"
                                        value="#{msg['rating']}">
                                        <a4j:actionparam name="h" value="getSelectedMark()"
                                            assignTo="#{myBean.mark}" noEscape="true" />
                                    </a4j:commandLink>
            
                <script type="text/javascript" language="javascript">
                    //<![CDATA[
                function getSelectedMark() {
                    var rates = document.getElementsByName("rating");
                    for (i = 0; i < rates.length; i++) {
                        if(rates[i].checked == true) {
                            return rates[i].value;
                        }
                    }
            
                    return 0;
                }
                //]]>    
            </script>