简体   繁体   English

Primefaces只有可拖动的事件

[英]Primefaces draggable event only

I want to make a list of primefaces panels draggable and i want to catch the event in order to save the position. 我想制作一个可拖动的primefaces面板列表,我想抓住事件以保存位置。 Is that possible? 那可能吗? Thank you, i am here for further explanation 谢谢,我在这里进一步解释

The jquery method that i have used: 我使用的jquery方法:

$(function() {
 $(" .dragPanel").draggable({
  start: function() { },
  drag: function() {
      var theId= $( this).attr("id");
      $("#form0\\:thePanelId").val(theId);
      var offset = $( this ).offset();
      var left = offset.left;
      var top = offset.top;

      var parent = $(window);

      var leftParent = parent.width();
      var topParent = parent.height();

      $("#form0\\:left").val(100*left/leftParent);
      $("#form0\\:top").val(100*top/topParent);
      $("#form0\\:leftParent").val(leftParent);
      $("#form0\\:topParent").val(topParent);
  },

  stop: function() {
    jQuery( "[id$='buttonId']" ).click();
 } });
  })

form snippet : 表格摘要:

   <p:inputText id="left" value="#{reportDetailsManagedBean.left}" style="display: none;"> </p:inputText>
   <p:inputText id="top" value="#{reportDetailsManagedBean.top}" style="display: none;"> </p:inputText>
   <p:inputText id="leftParent" value="#{reportDetailsManagedBean.leftParent}" style="display: none;"> </p:inputText>
   <p:inputText id="topParent" value="#{reportDetailsManagedBean.topParent}" style="display: none;"> </p:inputText>
   <p:inputText id="thePanelId" value="#{reportDetailsManagedBean.thePanelId}" style="display: none;"></p:inputText>

   <h:commandButton id="buttonId" actionListener="#{reportDetailsManagedBean.saveDragChange()}" style="display: none;" />

If you want to change the button upload the form with ajax change by 如果您想更改按钮,请使用ajax更改方式上传表单

<h:commandButton id="buttonId" style="display: none;" 
 actionListener="#{reportDetailsManagedBean.saveDragChange()}"  >
    <f:ajax execute="@form" render=":rootViewId" />
</h:commadButton>

This execute="@form" will upload the entire form, `render=":rootViewId" will search for the id from the root view of the document and will upload any changes made to bean. 这个execute="@form"将上传整个表单,`render =“:rootViewId”将从文档的根视图中搜索id,并将上传对bean所做的任何更改。

other way to do it and I like more since you're using primefaces . 其他方式做到这一点,我喜欢更多,因为你正在使用primefaces Is to use the pf commandButton that is ajax based for default 是使用默认为ajax的pf commandButton

<p:commandButton id="buttonId" style="display: none;" 
 actionListener="#{reportDetailsManagedBean.saveDragChange()}" update="@form" />

the attribute in the <p:commandButton update will update the form after the ajax is completed <p:commandButton update的属性将在ajax完成后更新表单

I hope this help you , greets 我希望这能帮助你,迎接你


Edited 编辑

About just working for the first drag... 关于刚刚为第一次拖动工作......

In this line Im not sure is this works: 在这一行我不确定这是否有效:

but you better use typical jquery sintax 但你最好使用典型的jquery sintax

replace: 更换:

jQuery( "[id$='buttonId']" ).click();

by 通过

$("#buttonId").click();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM