ADF里通过程序化实现Model层动态LOV

前一阵在苏州CDC向同事们deliver ADF经典课程的时写的一个小案例,仅供ADF使用者参考。

前提:

 1. 在EmployeeVO上创建了一个View Accessor: DepartmentVO1。DepartmentVO1没有WHERE定义,没有Named View Criteria定义。

 2. 在EmployeeVO的DepartmentId属性上以DepartmentVO1作为DataSource创建了一个declarative的LOV,List Attribute也是DepartmentId.

要求:下拉EmployeeVO的DepartmentId的LOV时可选项根据当前员工的不同而发生变化(可以是任何业务逻辑)。

因为要求是更具任何业务逻辑,所以只能采用coding的方式了。

我是这样做的(随便写了个逻辑:只有比当前部门编号大50之内的部门才可选):

a. 生成EmployeeVO的ViewRow类。

b. 在ViewRow类里覆盖getDepartmentId():

    public Number getDepartmentId() {

        Number currentValue = (Number) getAttributeInternal(DEPARTMENTID);

        RowSet rs  = this.getDepartmentVO1();
        ViewObject dept = rs.getViewObject();

        Number limitValue = currentValue.add(50);

        /* ViewCriteria method. */
        dept.applyViewCriteria(null);
        ViewCriteria vc = dept.createViewCriteria();
        ViewCriteriaRow vr = vc.createViewCriteriaRow();
        vr.setAttribute("DepartmentId", "< "+limitValue.toString());
        vc.addElement(vr);
        dept.applyViewCriteria(vc);
        /* */

        return currentValue;
    }

运行BC Browser或是托到JSF上试试吧。 注意,先在BC Browser上测试,然后在JSF上测试可能会有惊喜哦,试着解决一下吧 =D

-完-

另外,ADF这么些年在国内的普及率真是令我痛心疾首,和国外相比差距太大!好东西没有人用、不会用、害怕用,实在是着急。作为国内最早使用ADF的一批人之一,我觉得自己也有很大的责任。ADF需要大家的爱护。

http://www.databi.cn/forum-57-1.html上我斑竹了一个ADF的论坛,国内的或是汉语的ADF使用者和爱好者有问题直接到那里去问我,我尽量召集一些国内的ADF Developer去那里,大家互相切磋一下,现在ADF和SOA暂时是一个版。otn用户可以直接去这里https://forums.oracle.com/forums/forum.jspa?forumID=83

希望ADF走得更快,走得更远,Java在Oracle这里走好。

Todd


评论:

Technically, ADF is superb.But it is not users' fault at all whichever region he is in. Oracle did not promote ADF hard enough or in the right direction. It was proprietary. JDev was chargeable. Many users chose to use open source framework. More than 10 years ago, I started using BC4J and at that time there was little documentation on that. It was moved to ADF later. Still very little information. I gave up. How did users feel? I don't have to use your framework to get my jobs done. Over years, Oracle has been spending a lot to promote ADF and now it is getting popular more and more. But the cake was already cut.

发表于 guest 在 2013年06月06日, 02:13 上午 CST #

You share my feeling about the little information part in the early days.

And I strongly agree with that users have no fault.

As an Oracle employee I feel there is a lot of things we should do to help ADF become better and better.

As an instructor, what I've observed is:

8 years ago, my ADF class opens twice per year;
Now, twice per month...

My locking mode is more optimistic, I believe that the cake is always in an single state of - "cutting". =D

发表于 Todd 在 2013年06月06日, 12:26 下午 CST #

发表一条评论:
  • HTML语法: 禁用
About

Principal Instructor

甲骨文首席培训师

来论坛找我

SHOUG

Search

Categories
Archives
« 四月 2014
星期日星期一星期二星期三星期四星期五星期六
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
今天