我在Websphere上使用JSF + Primefaces试图创建一个像胶粘物的应用程序。
当使用onDrop监听器时,我很难从重复控件获取属性(在这种情况下为位置的样式)。这是我的代码:
board.xhtml
<h:form id="mainForm">
<p:dataList id="restPanel" styleClass="restrictPanel" var="note"
value="#{publicBoard.getNotes()}" columns="1" type="none">
<p:panel id="note" header="#{note.title}" styleClass="smallNote"
style="#{publicBoard.getNoteStyle(note)}">
<h:outputText value="#{note.description}" />
</p:panel>
<p:draggable for="note" containment="parent" opacity="0.3" />
</p:dataList>
<p:droppable for="mainForm" datasource="restPanel">
<p:ajax process="@form" listener="#{publicBoard.onDrop}" />
</p:droppable>
</h:form>
publicBoard
bean
public void onDrop(DragDropEvent ddEvent) {
Note obj = (Note) ddEvent.getData();
System.out.println("NOTE ID:" + obj.getId());
System.out.println(ddEvent.getDragId());
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
UIComponent component = viewRoot.findComponent(ddEvent.getDragId());
if(component!=null){
System.out.println(component.getId());
}else{
System.out.println("NULL COMPONENT");
}
}
结果
[22.07.15 14:27:16:094 CEST] 000000c8 SystemOut O NOTE ID:4
[22.07.15 14:27:16:094 CEST] 000000c8 SystemOut O mainForm:restPanel:3:note
[22.07.15 14:27:16:094 CEST] 000000c8 SystemOut O NULL COMPONENT
任何帮助将不胜感激!