在ADF中使用AutoSuggest

在ADF中使用AutoSuggest

概述

在使用Google/Baidu的时候我们经常会注意到,在搜索框中进行文字输入的时候,经常会根据当前输入的内容自动关联出以该内容开头的相关内容,这就是AutoSuggest,在Oracle ADF 11g中可以方便地实现AutoSuggest。 实现 1、创建ADF Application,为Model项目创建数据库连接,基于HR Schema的Departments表创建EO/VO/AM,并将该VO实例添加到AM的Data Model中 2、生成AM的实现类,增加如下代码到该类:
public List getDepartmentName() { ViewObjectImpl departments = this.getDepartmentsView1(); departments.executeQuery(); departments.reset(); List; departmentNames = new ArrayList(); while (departments.hasNext()) { String departmentName = (String)departments.next().getAttribute("DepartmentName"); departmentNames.add(departmentName); } return departmentNames; }
3、在ViewController项目中创建新页面,对页面进行适当布局,拖动af:InputText到界面
4、从控件面板中选择“autoSuggestBehavior”,添加到上一步骤的af:InputText组件中,并绑定suggestItems到该BackingBean中的属性suggestedItems
5、为页面生成PageDef,添加基于Departments表创建的VO实例到该PageDef文件中
6、在Backingbean中编写suggestionItems()方法的代码如下:
public List suggestedItems(String string) { List selectItems = new ArrayList(); BindingContext bc = BindingContext.getCurrent(); DCBindingContainer binding = (DCBindingContainer)bc.getCurrentBindingsEntry(); OperationBinding op = binding.getOperationBinding("getDepartmentName"); op.execute();
   if (op.getErrors() != null && op.getErrors().size() > 0) {     List; departmentNames = (List)op.getResult();
     for (String departmentName : departmentNames) {
       if (departmentName.startsWith(string)) {
         selectItems.add(new SelectItem(departmentName, departmentName));
       }
     }
   }
   return selectItems;
 }

7、保存并运行该应用,结果如图:
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值