我想拖动项目并将其放入仪表板。我可以使用可拖动的outputLabel组件,但我无法将其放入仪表板中。在仪表板的droppable标签中,p:ajax监听器元素不起作用。我该如何解决?或者我的错误在哪里?任何人都可以帮助我吗?
这是我的bean函数:
public void f_onCompDrop(DragDropEvent ddEvent) {
FacesContext fc = FacesContext.getCurrentInstance();
Application application = fc.getApplication();
dashboard = (Dashboard) application.createComponent(fc, "org.primefaces.component.Dashboard",
"org.primefaces.component.DashboardRenderer");
UIComponent comp = ddEvent.getComponent().findComponent(ddEvent.getDragId());
dashboard.setId(ddEvent.getDropId());
getDashboardComponents();
DashboardModel model = new DefaultDashboardModel();
for (int i = 0; i < 3; i++) {
DashboardColumn column = new DefaultDashboardColumn();
model.addColumn(column);
}
dashboard.setModel(model);
if (comp.getId().startsWith("out", 0)) {
OutputTextBean out = new OutputTextBean();
OutputLabel outputLbl = new OutputLabel();
outputLbl.setId("out_" + out.getID());
outputLbl.setValue("Dragged");
model.getColumn(0).addWidget(outputLbl.getId());
}
components.add(comp);
}
这是我的xhtml文件:
<!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>
<style type="text/css">
.ui-widget {
font-size: 75%;
}
.ui-layout-west {
z-index:20 !important;
overflow:visible;
}
.ui-layout-west .ui-layout-unit-content {
overflow:visible;
}
</style>
</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" >
<p:outputLabel id="out_1" value="outputlabel"/>
<p:draggable for="out_1" helper="clone"/>
</p:layoutUnit>
<p:layoutUnit id="middle" position="center" >
<p:tabView>
<p:tab title="Page 1">
<p:dashboard id="dashboard" binding="#{myBean.dashboard}" style="width: 600px; height: 600px;">
</p:dashboard>
<p:droppable for="dashboard" >
<p:ajax listener="#{myBean.f_onCompDrop}" update="dashboard"/>
</p:droppable>
</p:tab>
</p:tabView>
</p:layoutUnit>
</p:layout>
</h:body>
</f:view>
</html>
答案 0 :(得分:1)
错误在于你忘记了表格。在正文的开始标记后添加<h:form>
,在正文结束标记之前添加</h:form>
。