Question

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>
Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top