ADF11g-007:ADF中如何将两个独立的LOV实现级联

在网上看到很多基于一个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

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

 

 

 


 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值