Primefaces Tree节点可拖动到子级

时间:2018-07-04 11:44:01

标签: jsf primefaces tree

我有一棵PrimeFaces(6.2.5)树,在其中启用了可拖动和可拖放。我对此有一些问题,并且在我弄清楚这一点的同时,已经通过jquery手动实现了拖放;

   <div class="plantree" id="realplantree">
   <p:tree id="plantree" value="#{curriculumngTreeFacade.root}" var="node" dynamic="false" selectionMode="single" selection="#{curriculumngTreeFacade.selectedNode}" draggable="true" droppable="true">
        <p:ajax event="select" listener="#{curriculumngTreeFacade.onNodeSelect}"  update="administration-form:curriculummain" oncomplete="initDNDPlan();"/>
        <p:ajax event="expand" listener="#{curriculumngTreeFacade.onNodeExpand}" />
        <p:ajax event="collapse" listener="#{curriculumngTreeFacade.onNodeCollapse}" />
        <p:ajax event="dragdrop" listener="#{curriculumngTreeFacade.onDragDrop}"/>
        <p:treeNode expandedIcon="ui-icon ui-icon-folder-open" collapsedIcon="ui-icon ui-icon-folder-collapsed">
          <h:outputText value="#{node}"/>
        </p:treeNode>
    </p:tree>
</div>

我的问题是:

  • 我尚未在p:ajax事件中添加“ update ='plantree'”变量 用于拖放。即使如此,如果我尝试将父类别拖到 子类别,它会破坏我的树,因为UI会尝试更新。一世 实际上在后端运行检查父/子连接 代码,如果是这种情况,我不会更新树,但是在这种情况下 在这种情况下,我的支持bean中的方法甚至没有在 树爆炸。它在PrimeFaces Showcase
  • 上的作用相同

备用代码:

public void onDragDrop(TreeDragDropEvent event) throws Exception {
TreeNode dragNode = event.getDragNode();
TreeNode dropNode = event.getDropNode();

int dropIndex = event.getDropIndex();
if (dragNode.getData() instanceof CurriculumCategoryMetaModel && dropNode.getData() instanceof CurriculumCategoryMetaModel) {

  CurriculumCategoryMetaModel drop = (CurriculumCategoryMetaModel) dropNode.getData();
  CurriculumCategoryMetaModel drag = (CurriculumCategoryMetaModel) dragNode.getData();

  if (drop.getType() == drag.getType() && drag.getClassid() > 0) {
    drag.setParent(drop);
    CurriculumBuilderProvider provider = CurriculumBuilderProvider.getProvider(drop.getType());
    provider.saveCategory(drag, UserSessionFacade.getUserLocale());
    this.initialize();
    expandCategory(root, drop.getClassid(), drop.getType());
  } else {
    this.initialize();
  }

}

FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Dragged " + dragNode.getData(), "Dropped on " + dropNode.getData() + " at " + dropIndex);
FacesContext.getCurrentInstance().addMessage(null, message);
List<String> updates = new ArrayList<>();
updates.add("administration-form:curriculummenu");
updates.add("administration-form:growl");
PrimeFaces.current().ajax().update(updates);

}

private boolean dragIsParentOfDrop(CurriculumCategoryMetaModel drop, CurriculumCategoryMetaModel drag) {
CurriculumCategoryMetaModel parent = drop.getParent();
while (parent != null) {
  if (parent.getClassid() == drag.getClassid()) {
    return true;
  } else {
    parent = parent.getParent();
  }
}
return false;

}

  • 是否可以添加可以放入的已接受节点。我有2个 根节点,用于不同类别,并且不允许拖动 并在它们之间掉落。实际上,我什至不希望根节点成为 可拖动的。在图片上,“学习路径”和“临时”不应拖动,因为它们只是下面类别的容器。 enter image description here

0 个答案:

没有答案