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

    Submit JavaScript value to a4j:commandLink

    Sergey Morenets Novice



      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





      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?



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

          Try to use a4j:actionparam


          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)}"
                                        <a4j:actionparam name="h" value="getSelectedMark()"
                                            assignTo="#{myBean.mark}" noEscape="true" />
                <script type="text/javascript" language="javascript">
                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;