现象:
在ADF开发时,对于LOV大多数的处理时将LOV做成下拉框,本文简单介绍下使用<af:autoSuggestBehavior>。
步骤:
1.方法一
这里只做简单介绍,将VO中的Attrubute添加list of value,绑定对应lov ,页面中已文本框取代下拉框,详情参见小尹博客
http://blog.csdn.net/ygj26/article/details/8048157
2.方法二
避开绑定vo属性,适用范围比方法1要广点
1.创建LOV ,并自己编写查询方法。
public List searchPaper(String paperName){ List list = new ArrayList();
this.setRangeSize(-1);
this.setMaxFetchSize(-1);
this.setvarPaperName(paperName);
this.executeQuery();
for(int i =0;i<this.getEstimatedRowCount();i++){
list.add(this.getRowAtRangeIndex(i).getAttribute("PaperName"));
}
return list;
}
2.在页面定义文件中声明此方法。
<methodAction IterBinding="AdT23PaperView1Iterator" id="searchPaper"
RequiresUpdateModel="true" Action="invokeMethod"
MethodName="searchPaper" IsViewObjectMethod="true"
DataControl="AppModuleDataControl"
InstanceName="AppModuleDataControl.AdT23PaperView1">
<NamedData NDName="paperName"
NDValue="#{bindings.ExecuteWithParams_varPaperName}"
NDType="java.lang.String"/>
</methodAction>
3.编写工具类AutoSuggestBean
package azclportal.common.view.custom;
import azclportal.common.view.utils.ADFUtils;
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.SelectItem;
import oracle.binding.OperationBinding;
public class AutoSuggestBean {
private String operationBindingName;
private String paramName="value";
public AutoSuggestBean() {
super();
}
public List onSuggest(String value) {
ArrayList<SelectItem> selectItems = new ArrayList<SelectItem>();
if(operationBindingName != null) {
OperationBinding binding = ADFUtils.findOperation(operationBindingName);
if(binding != null) {
binding.getParamsMap().put(paramName, value);
List<String> results = (List<String>)binding.execute();
for(String result : results) {
selectItems.add(new SelectItem(result, result));
}
}
}
return selectItems;
}
public void setOperationBindingName(String operationBindingName) {
this.operationBindingName = operationBindingName;
}
public String getOperationBindingName() {
return operationBindingName;
}
public void setParamName(String paramName) {
this.paramName = paramName;
}
public String getParamName() {
return paramName;
}
}
4.文本框添加<af:autoSuggestBehavior>组件,将AutoSuggestBean绑定到taskFlow,组件的SuggestedItems绑定AutoSuggestBean中的onSuggest方法
5.很明显,AutoSuggestBean中两个property需要传入值的
operationBindingName:传入方法名,也就是我们绑定在页面定义文件中的LOV查询方法。即本文中的searchPaper。
paraName:传入参数名,查询方法中的参数 即本文中:paperName。
在taskFlow中进行传值
<managed-bean id="__1">
<managed-bean-name id="__2">AutoSuggestBean</managed-bean-name>
<managed-bean-class id="__3">azclportal.common.view.custom.AutoSuggestBean</managed-bean-class>
<managed-bean-scope id="__4">request</managed-bean-scope>
<managed-property id="__11">
<property-name id="__10">operationBindingName</property-name>
<property-class></property-class>
<value id="__9">searchPaper</value>
</managed-property>
<managed-property id="__14">
<property-name id="__12">paramName</property-name>
<value id="__13">paperName</value>
</managed-property>
</managed-bean>
到这里基本就结束了,下面来看看效果图
效果图: