Developer Tools
JDeveloper
In the source editor, add the following
import statements before the
public class line:
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;
Then after:
public class MyPage {
public MyPage() {
}
Add the following method that returns a List of
SelectItem items for populating a listbox programmatically:
/**
* @return the beverage items
*/
private List<SelectItem> _choices;
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;
}
Next, add the following
DndAction method that handles a drop event:
/**
* Drop event handler
*/
public DnDAction handleItemDrop(DropEvent dropEvent) {
try {
DataFlavor<String> df = DataFlavor.getDataFlavor(String.class);
String droppedValue = dropEvent.getTransferable().getData(df);
if (droppedValue == null) {
return DnDAction.NONE;
} else {
_choices.add(new SelectItem(droppedValue, droppedValue));
}
return DnDAction.COPY;
} catch (Exception ex) {
System.out.println("item drop failed with : " + ex.getMessage());
return DnDAction.NONE;
}
}
In the sample, when an item is dropped on the listbox, the listbox refreshes to show the new list of items.
Instead of typing the sample code, you can copy the code in this window and then paste it into the source editor.
Copyright © 1997, 2009, Oracle. All rights reserved.