在网上看到很多基于一个VO中的两个Atttribute的lov实现级联的例子,本文描述如何将两个独立的lov实现级联,以Oracle实例数据库HR中的DEPARTMENTS和LOCATIONS两个表为例,根据DEPARTMENT中的列location_id过滤department列表的值。
1.建立ADF项目DepartmentView的Query如下
SELECT Departments.DEPARTMENT_ID,Departments.DEPARTMENT_NAME,Departments.MANAGER_ID,Departments.LOCATION_ID FROM DEPARTMENTS Departments WHERE (Departments.LOCATION_ID = :locationId or :locationId is null)
locationId的值设置为adf.context.requestScope.
locationIdvlaueType选择Expression
2.建backing Bean
package view; import javax.faces.component.UIComponent; import javax.faces.event.ValueChangeEvent; import oracle.adf.model.binding.DCIteratorBinding; import oracle.adf.share.ADFContext; import oracle.jbo.Row; import oracle.jbo.server.ViewRowImpl; import oracle.jbo.uicli.binding.JUCtrlListBinding; import oracle.jbo.uicli.binding.JUIteratorBinding; public class CascadelovBean { /** * 要获取触发lov的属性 */ private String attributeName; /** * 要传的参数名 */ private String parameterName; /** * 触发lov的List Binding */ private JUCtrlListBinding listBinding; /** * 被触发lov的Iterator Binding */ private DCIteratorBinding iteratorBinding; public CascadelovBean() { super(); } //获取下触发下拉列表的值,并将值放入Request Scope,VO中使用Groovy表达式取得 public void valuechangelistener(ValueChangeEvent valueChangeEvent) { if (valueChangeEvent.getNewValue() != valueChangeEvent.getoldValue()) { Integer newValue = (Integer)valueChangeEvent.getNewValue(); ViewRowImpl row = (ViewRowImpl)listBinding.getValueFromList(newValue); Object paramValue = row.getAttribute(attributeName); ADFContext.getCurrent().getRequestScope().put(parameterName,paramValue); iteratorBinding.executeQuery(); } } public void setListBinding(JUCtrlListBinding listBinding) { this.listBinding = listBinding; } public JUCtrlListBinding getListBinding() { return listBinding; } public void setIteratorBinding(DCIteratorBinding iteratorBinding) { this.iteratorBinding = iteratorBinding; } public DCIteratorBinding getIteratorBinding() { return iteratorBinding; } public void setAttributeName(String attributeName) { this.attributeName = attributeName; } public String getAttributeName() { return attributeName; } public void setParameterName(String parameterName) { this.parameterName = parameterName; } public String getParameterName() { return parameterName; } }
3.配置backing Bean,给CascadelovBean中的属性赋值
<?xml version="1.0" encoding="UTF-8" ?> <adfc-config xmlns="http://xmlns.oracle.com/adf/controller" version="1.2"> <managed-bean id="__2"> <managed-bean-name id="__3">CascadelovBean</managed-bean-name> <managed-bean-class id="__1">view.CascadelovBean</managed-bean-class> <managed-bean-scope id="__4">request</managed-bean-scope> <managed-property id="__7"> <property-name id="__5">listBinding</property-name> <value id="__6">#{bindings.LocationList}</value> </managed-property> <managed-property id="__9"> <property-name id="__10">iteratorBinding</property-name> <value id="__8">#{bindings.DepartmentsView1Iterator}</value> </managed-property> <managed-property id="__12"> <property-name id="__11">attributeName</property-name> <value id="__13">LocationId</value> </managed-property> <managed-property id="__16"> <property-name id="__14">parameterName</property-name> <value id="__15">locationId</value> </managed-property> </managed-bean> </adfc-config>
4. 页面,给location list绑定CascadelovBean的valuechangelistener方法,将Department List的partialTriggers指向Location List
<af:panelFormlayout id="pfl1"> <af:selectOneChoice label="Location" value="#{bindings.LocationList.inputValue}" id="soc1" valuechangelistener="#{CascadelovBean.valuechangelistener}" autoSubmit="true"> <f:selectItems value="#{bindings.LocationList.items}" id="si1"/> </af:selectOneChoice> <af:selectOneChoice label="Department" value="#{bindings.DepartmentList.inputValue}" id="soc2" partialTriggers="soc1"> <f:selectItems value="#{bindings.DepartmentList.items}" id="si2"/> </af:selectOneChoice> <af:commandButton actionListener="#{bindings.ExecuteWithParams.execute}" text="Search" disabled="#{!bindings.ExecuteWithParams.enabled}" id="cb1"/> </af:panelFormlayout>
程序包请到以下连接下载
http://download.csdn.net/detail/ygj26/4077019
或