p:spinner p:ajax and f:param mixed together, bean method executed multiple times

475 views Asked by At

I'm developping with Primefaces 4.0, JSF Mojarra 2.1.7 and jBoss_7.1.1_Final.

The tool I'm creating is mainly a dialog window showing a dataTable with dynamic columns (p:columns)

Those dynamic columns show a pSpinner like this :



                                        <p:spinner id="updateQj_#{colIndex}_#{rowQj.idQbt}" widgetVar="updateQjJs_#{colIndex}_#{rowQj.idQbt}" stepFactor="1" min="0" max="#{rowQj.qbtType}"
                                                    value="#{rowQj.quantiteDuJour(qjColonne.property)}" onkeydown="return false;"
                                                    styleClass="editQj" rendered="#{not verrouille}" title="Cliquez ici pour modifier la quantité journalière" >

                                            <p:ajax listener="#{recherche.updateQj}" update="@this, :formRecherche:growl" process="@this"/>
                                            <f:param name="idQbt" value="#{rowQj.idQbt}"/>
                                            <f:param name="jour" value="#{qjColonne.property}"/>
                                            <f:param name="ligne" value="#{rowIndex}"/>
                                            <f:param name="colonne" value="#{colIndex}"/>
                                        </p:spinner>                                        
                                </p:column>                                             
                            </p:columns>    

Everything seems to be working fine till for some unknown reason, the click in one of the columns modifies the current value plus the one previously updated in another column. To see it clearly: if I keep clicking/updating spinners in the same column everything works fine. If I click a spinner of another column it updates both. Any idea would be greatly appreciated.

1

There are 1 answers

2
alaakaazaam On BEST ANSWER

in primefaces4, p:spinner in a cell made of p:columns>p:column doesn't behave like it should, first clicks work but at some moments, a simple click generates incessant ajax calls as if i clicked each spinner in each cell...After several days of workaround, and thinking that pf makes usage of jquery under the cover i tried by myself. Surprisingly, firebug console logged 'spinner is not a function' and jquery.ui.version was 1.10.3 so i downloaded 1.10.4 on jquery's site and included it in my header after other javascripts. jquery.ui.version showed 1.10.4 and no more error message appeared. :) Finally, i wrote this in each p:column of p:columns in a p:datatable

    <input id="updateQj_#{rowIndex}_#{colIndex}_#{rowQj.idQbt}"    widgetVar="updateQjJs" class="editQj"     value="#{rowQj.listeDesQj[colIndex].quantiteRealisee}"> ‌​ 
</input> 
<script type="text/javascript"> 
    jQuery("input[id=updateQj_#{rowIndex}_#{colIndex}_#{rowQj.idQbt}]")
    .spinner‌​({  min:0, 
                max:#{rowQj.qMax}, 
                step:1, 
                change:function(){ rmt_updateQj([parameters]); } }); 
</script>