我有一棵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>
我的问题是:
备用代码:
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;
}