您的位置:首页 > 其它

Groovy在ADF BC中的常见用法之一

2015-08-07 14:30 369 查看
开发运行环境:JDeveloper 11.1.2.4

1. 设置EO或VO的Attribute值

(1)在Employees EO上增加一个Attribute:AnnualSalary,Expression: (Salary != null ? Salary : 0 ) * 12。

(2)如果需要引用EntityImpl类中的自定义方法,需要加前缀:adf.object。

比如:adf.object.getDefaultSalaryForGrade()。

这里,adf.object指向的是当前EntityImpl。

2. 定义在EO的Attribute上的验证规则

(1)在Employees EO的Salary Attribute增加一个验证规则:

if (JobId == "SA_REP"){

return newValue < 1000

} else

return true

在验证规则中reference一个Attribute时,Attribute-level的验证规则首先被触发,验证该Attribute的newValue值。newValue是用户输入后改变的值,oldValue是改变之前的值。

(2)在Employees EO的Salary Attribute增加另一个验证规则,其中调用了EntityImpl类中的自定义方法:getMaxSalaryForGrade。

if (JobId == "SA_MAN"){
return newValue < source.getMaxSalaryForGrade(JobId)
} else
return true

注意,reference方法前要加前缀“source”。

3. 访问EntityImpl类的自有方法

(1)Override create方法

/**

* Add attribute defaulting logic in this method.

* @param attributeList list of attribute names/values to initialize the row

*/

protected void create(AttributeList attributeList) {

super.create(attributeList);

SequenceImpl seq = new SequenceImpl("EMPLOYEES_SEQ", getDBTransaction());

oracle.jbo.domain.Number seqNextVal = seq.getSequenceNumber();

setEmployeeId(Integer.valueOf(seqNextVal.intValue()));

}

这样修改后,EmployeeId的值将从Sequence中获取。

(2)如果你不想Override create方法,也可以直接使用Groovy表达式来获取Sequence的下一个值。

设置EmployeeId的Expression:(new oracle.jbo.server.SequenceImpl("EMPLOYEES_SEQ",adf.object.getDBTransaction())).getSequenceNumber()

注意,这里必须写全类SequenceImpl的路径名。

(3)如果你觉得(2)的方式有些不直观,可以在EntityImpl中定义一个Help方法。

public oracle.jbo.domain.Number nextVal(String sequenceName) {
SequenceImpl s = new SequenceImpl(sequenceName, getDBTransaction());
return s.getSequenceNumber();
}

然后,设置EmployeeId的Expression:adf.object.nextVal("EMPLOYEES_SEQ")。

4. 访问hints属性

(1)如果想访问LastName的label属性,可以这样写:adf.object.hints.LastName.label。

(2)如果在error message中想访问LastName的label属性,可以这样写:source.hints.LastName.label。

文章来自:
http://maping930883.blogspot.com/2013/06/adf233groovyadf-bc.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: