0

I have a little script for drag&drop a table and it's working fine. But I've a problem: I have to pass the start/endPosition to my BackingBean. Is there a way to call a BackingBean function from jquery (with parameters)? Or do you know some nice workaround?

Code for drag&drop:

<script type="text/javascript" language="javascript">
$(document).ready(function() {
    var startPosition;
    var endPosition;
    $('#table tbody').sortable({
    cursor: "move",
    start:function(event, ui){
      startPosition = ui.item.prevAll().length;
    },
    update: function(event, ui) {
      endPosition = ui.item.prevAll().length;

      // Call BackingBean function

     }
    });
});
</script>
thomas.st
  • 393
  • 2
  • 5
  • 17

2 Answers2

0

BackingBean is Server Side, what you could do is make a call to a javascript function in you backingbean code, and of course changing your function to return both the start and end position.

KoU_warch
  • 2,160
  • 1
  • 25
  • 46
0

You can have two hidden input fields in your xhtml page like

  <h:inputHidden id="input1" value="#{bean.startPosition}" /> // getters and setters for startPosition in your bean
  <h:inputHidden id="input2" value="#{bean.endPosition}" /> 

and set the values which your are getting from the above Jquery Script to these fields

   document.getElementById('form:input1').value=startPosition;
   document.getElementById('form:input2').value=endPosition;

and get them in the bean.It should do your job.

SRy
  • 2,901
  • 8
  • 36
  • 57
  • Thanks for you answer, I already did that with BalusC's code (http://balusc.blogspot.co.at/2009/05/javajspjsf-and-javascript.html#PassVariablesFromClientSideToServerSide). I made a new form, which I hide in my jquery code ($('form').hide()). – thomas.st Nov 09 '12 at 19:02