问题
I have 4 layout units in full-page Primefaces layout. I have outputlabel in west layout unit. I want to drag it and drop it to center layout-unit. The drop area which I want to drop output label to here is a panel in tabView. When I start the dragging outputLabel don't go out from west layout-unit. Also when I drag it to out of west layout-unit it disappears. How can I solve my problem? I've been working on it for 2 days but I haven't succeed.
Here is my code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html">
<h:head>
</h:head>
<h:body>
<p:layout fullPage="true">
<p:layoutUnit id="top" position="north" header="menu" size="100">
</p:layoutUnit>
<p:layoutUnit id="bottom" position="south" header="properties" size="100">
</p:layoutUnit>
<p:layoutUnit id="left" position="west" header="toolbox" size="200" style="overflow: visible" >
<p:outputLabel id="out1" value="outputlable"/>
<p:draggable for="out1" helper="clone"/>
</p:layoutUnit>
<p:layoutUnit id="middle" position="center" header="sayfa 1" >
<p:tabView>
<p:tab id="drop_page_1" title="Page 1">
<p:panel rendered="#{empty myBean.components}">
Please drag any component to here.
</p:panel>
<p:panel id="tab_panel" rendered="#{not empty myBean.components}">
</p:panel>
</p:tab>
<p:droppable id="drop_page_1" for="page_1" >
<p:ajax listener="#{myBean.f_onCompDrop}" />
</p:droppable>
</p:tabView>
</p:layoutUnit>
<p:droppable for="middle" >
<p:ajax listener="#{myBean.f_onCompDrop}" />
</p:droppable>
</p:layout>
</h:body>
</f:view>
</html>
And here my bean:
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.primefaces.event.DragDropEvent;
import java.util.List;
import javax.faces.component.UIComponent;
@ManagedBean(name="myBean")
@SessionScoped
public class NewJSFManagedBean {
private List<UIComponent> components;
public NewJSFManagedBean() {
}
public void f_onCompDrop(DragDropEvent ddEvent) {
UIComponent comp = ddEvent.getComponent().findComponent(ddEvent.getDragId());
components.add(comp);
}
public List<UIComponent> getComponents() {
return components;
}
public void setComponents(List<UIComponent> components) {
this.components = components;
}
}
回答1:
I had the same problem of dragging items between 2 layout units. I solved it completly via css.
I altered the container where I wanted to drag out of by changing the 'overflow' property to 'visible'.
The second thing I did, was changing the 'z-index' property of the container I wanted to drag into and drop, to a negative value. That fixed it for me.
回答2:
My issue with drag and drop between primefaces layouts was fixed in the draggable component, by adding appendTo="@(body)" and zindex="5" Draggable component looks like:
<p:draggable for="dragIcon" revert="true" helper="clone" appendTo="@(body)" zindex="5"/>
来源:https://stackoverflow.com/questions/20348499/drag-and-drop-between-different-layout-units-in-primefaces