运行结果:
运行日志如下:package project1; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.faces.model.SelectItem; import oracle.adf.view.rich.datatransfer.DataFlavor; import oracle.adf.view.rich.dnd.DnDAction; import oracle.adf.view.rich.event.DropEvent; //@ManagedBean(name="dnd") //@SessionScoped public class MyPageInfo implements Serializable { public MyPageInfo() { } /** * @return the beverage items */ private List<SelectItem> _choices; boolean ifContain = false; public List<SelectItem> getChoices() { if (_choices == null) { _choices = new ArrayList<SelectItem>(); _choices.add(new SelectItem("Cocoa", "Cocoa")); _choices.add(new SelectItem("Tea", "Tea")); _choices.add(new SelectItem("Wine", "Wine")); } return _choices; } /** * Drop event handler */ public DnDAction handleItemDrop(DropEvent dropEvent) { System.out.println("----------------------Start of Drop event handler-------------------------"); try { DataFlavor<String> df = DataFlavor.getDataFlavor(String.class); String droppedValue = dropEvent.getTransferable().getData(df); System.out.println("====The value need to drop is " + droppedValue); if (droppedValue == null) { return DnDAction.NONE; } else { //If the item is already in the list, then do nothing;else append it to the list if (ifContain) { System.out.println("Have already in the list...."); System.out.println("----------------------End of Drop event handler-------------------------"); return DnDAction.COPY; } for (SelectItem item : _choices) { if (item.getLabel().equals(droppedValue)) { ifContain = false; } } if (!ifContain) { _choices.add(new SelectItem(droppedValue, droppedValue)); System.out.println("Have added to the list...."); ifContain = true; } System.out.println("----------------------End of Drop event handler-------------------------"); } return DnDAction.COPY; } catch (Exception ex) { System.out.println("item drop failed with : " + ex.getMessage()); return DnDAction.NONE; } } }