문제

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>
도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top