JDeveloper初步:ADF Faces页面拖放

概要:本教程,演示了如何将ADF Faces components定义为drag和drop targets,并实现事件监听。创建Managed bean MyPageInfo并且实现handleItemDrop监听器来处理drop event,并且在配置文件faces-config.xml定义一个实例dnd。faces-config.xml定义了,应用程序需要的资源,例如页面请求的files和beans等。事件处理函数handleItemDrop当拖动coffee到Beverage choices 列表时会出现多个相同内容的项,修改后的代码如下所示。

运行结果:


运行日志如下:
Target URL -- http://127.0.0.1:7101/DndApp-Project1-context-root/faces/MyPage.jspx
----------------------Start of Drop event handler-------------------------
====The value need to drop is Coffee
Have added to the list....
----------------------End of Drop event handler-------------------------
----------------------Start of Drop event handler-------------------------
====The value need to drop is Coffee
Have already in the list....
----------------------End of Drop event handler-------------------------
----------------------Start of Drop event handler-------------------------
====The value need to drop is Coffee
Have already in the list....
----------------------End of Drop event handler-------------------------


修改后的handleItemDrop

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;
        }
    }
}


参考【1】http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_41/jdtut_11r2_41.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值