ADF中如何将两个独立的LOV实现级联

来源:互联网 发布:点击访问fc2最新域名 编辑:程序博客网 时间:2024/06/15 19:25

在网上看到很多基于一个VO中的两个Atttribute的LOV实现级联的例子,本文描述如何将两个独立的LOV实现级联,以Oracle实例数据库HR中的DEPARTMENTS和LOCATIONS两个表为例,根据DEPARTMENT中的列location_id过滤department列表的值。

1.建立ADF项目DepartmentView的Query如下

[sql] view plaincopy
  1. SELECT Departments.DEPARTMENT_ID,   
  2. Departments.DEPARTMENT_NAME,   
  3. Departments.MANAGER_ID,   
  4. Departments.LOCATION_ID  
  5. FROM DEPARTMENTS Departments  
  6. WHERE (Departments.LOCATION_ID = :locationId or :locationId is null)  

locationId的值设置为adf.context.requestScope.

locationIdvlaueType选择Expression

 

 2.建Backing Bean

 

[java] view plaincopy
  1. package view;  
  2.   
  3. import javax.faces.component.UIComponent;  
  4. import javax.faces.event.ValueChangeEvent;  
  5.   
  6. import oracle.adf.model.binding.DCIteratorBinding;  
  7. import oracle.adf.share.ADFContext;  
  8.   
  9. import oracle.jbo.Row;  
  10. import oracle.jbo.server.ViewRowImpl;  
  11. import oracle.jbo.uicli.binding.JUCtrlListBinding;  
  12. import oracle.jbo.uicli.binding.JUIteratorBinding;  
  13.   
  14. public class CascadeLOVBean {  
  15.     /** 
  16.      * 要获取触发LOV的属性 
  17.      */  
  18.     private String attributeName;   
  19.     /** 
  20.      * 要传的参数名 
  21.      */  
  22.     private String parameterName;  
  23.     /** 
  24.      * 触发LOV的List Binding 
  25.      */  
  26.     private JUCtrlListBinding listBinding;  
  27.     /** 
  28.      * 被触发LOV的Iterator Binding 
  29.      */  
  30.     private DCIteratorBinding iteratorBinding;  
  31.       
  32.       
  33.     public CascadeLOVBean() {  
  34.         super();  
  35.     }  
  36.     //获取下触发下拉列表的值,并将值放入Request Scope,VO中使用Groovy表达式取得  
  37.     public void valueChangeListener(ValueChangeEvent valueChangeEvent) {  
  38.         if (valueChangeEvent.getNewValue() != valueChangeEvent.getOldValue()) {  
  39.             Integer newValue = (Integer)valueChangeEvent.getNewValue();  
  40.             ViewRowImpl row = (ViewRowImpl)listBinding.getValueFromList(newValue);  
  41.             Object paramValue = row.getAttribute(attributeName);   
  42.             ADFContext.getCurrent().getRequestScope().put(parameterName, paramValue);  
  43.             iteratorBinding.executeQuery();  
  44.         }  
  45.     }  
  46.       
  47.     public void setListBinding(JUCtrlListBinding listBinding) {  
  48.         this.listBinding = listBinding;  
  49.     }  
  50.   
  51.     public JUCtrlListBinding getListBinding() {  
  52.         return listBinding;  
  53.     }  
  54.   
  55.     public void setIteratorBinding(DCIteratorBinding iteratorBinding) {  
  56.         this.iteratorBinding = iteratorBinding;  
  57.     }  
  58.   
  59.     public DCIteratorBinding getIteratorBinding() {  
  60.         return iteratorBinding;  
  61.     }  
  62.   
  63.     public void setAttributeName(String attributeName) {  
  64.         this.attributeName = attributeName;  
  65.     }  
  66.   
  67.     public String getAttributeName() {  
  68.         return attributeName;  
  69.     }  
  70.   
  71.     public void setParameterName(String parameterName) {  
  72.         this.parameterName = parameterName;  
  73.     }  
  74.   
  75.     public String getParameterName() {  
  76.         return parameterName;  
  77.     }  
  78. }  

3.配置Backing Bean,给CascadeLOVBean中的属性赋值

[html] view plaincopy
  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <adfc-config xmlns="http://xmlns.oracle.com/adf/controller" version="1.2">  
  3.   <managed-bean id="__2">  
  4.     <managed-bean-name id="__3">CascadeLOVBean</managed-bean-name>  
  5.     <managed-bean-class id="__1">view.CascadeLOVBean</managed-bean-class>  
  6.     <managed-bean-scope id="__4">request</managed-bean-scope>  
  7.     <managed-property id="__7">  
  8.       <property-name id="__5">listBinding</property-name>  
  9.       <value id="__6">#{bindings.LocationList}</value>  
  10.     </managed-property>  
  11.     <managed-property id="__9">  
  12.       <property-name id="__10">iteratorBinding</property-name>  
  13.       <value id="__8">#{bindings.DepartmentsView1Iterator}</value>  
  14.     </managed-property>  
  15.     <managed-property id="__12">  
  16.       <property-name id="__11">attributeName</property-name>  
  17.       <value id="__13">LocationId</value>  
  18.     </managed-property>  
  19.     <managed-property id="__16">  
  20.       <property-name id="__14">parameterName</property-name>  
  21.       <value id="__15">locationId</value>  
  22.     </managed-property>  
  23.   </managed-bean>  
  24. </adfc-config>  

4. 页面,给location list绑定CascadeLOVBean的valueChangeListener方法,将Department List的partialTriggers指向Location List

[html] view plaincopy
  1. <af:panelFormLayout id="pfl1">  
  2.               <af:selectOneChoice label="Location"  
  3.                                   value="#{bindings.LocationList.inputValue}"  
  4.                                   id="soc1"  
  5.                                   valueChangeListener="#{CascadeLOVBean.valueChangeListener}"  
  6.                                   autoSubmit="true">  
  7.                 <f:selectItems value="#{bindings.LocationList.items}" id="si1"/>  
  8.               </af:selectOneChoice>  
  9.               <af:selectOneChoice label="Department"  
  10.                                   value="#{bindings.DepartmentList.inputValue}"  
  11.                                   id="soc2" partialTriggers="soc1">  
  12.                 <f:selectItems value="#{bindings.DepartmentList.items}"  
  13.                                id="si2"/>  
  14.               </af:selectOneChoice>  
  15.               <af:commandButton actionListener="#{bindings.ExecuteWithParams.execute}"  
  16.                                 text="Search"  
  17.                                 disabled="#{!bindings.ExecuteWithParams.enabled}"  
  18.                                 id="cb1"/>  
  19.             </af:panelFormLayout>  

 

程序包请到以下连接下载

http://download.csdn.net/detail/ygj26/4077019

http://www.jdeveloper.com.cn/forum.php?mod=viewthread&tid=7


转自:http://blog.csdn.net/ygj26/article/details/7277447

0 0
原创粉丝点击