您的位置:首页 > 其它

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

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

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

[sql] view
plaincopy

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

[java] view
plaincopy

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中的属性赋值

[html] view
plaincopy

<?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

[html] view
plaincopy

<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

转自:http://blog.csdn.net/ygj26/article/details/7277447
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐