Oracle allowing Groovy expressions to be used in attribute validation and as a source for attribute values.
Entity Object Attribute and Raise error Groovy
The validation provides implicit object to access information contained within. Two of these information is oldValue and newValue, which gives you a handle to the value as it was before and after update.
.
If you want to raise a error message for high salary and low salary then you can use single validation to raise these error messages.
EX: in Create a attribute level script validation in the EO.
if(newValue > 10000)
{
adf.error.raise("EMPLOYEE_SALARY_IS_TOO_HIGH")
return false
}
if(newValue < 999)
{
adf.error.raise("EMPLOYEE_SALARY_IS_TOO_LOW")
return false
}
return true
Create these "EMPLOYEE_SALARY_IS_TOO_HIGH" and "EMPLOYEE_SALARY_IS_TOO_LOW" in the resource bundle.
Note: if you want raise a warning message use "adf.error.warn()".
Referencing custom methods in the EntityImpl class
If you have defined a method in your EntityImpl class, then this can be called as part of your expression for an attribute default:
adf.object.<your_custom_method>
Unlike when referencing an attribute of the entity object, which can be done by simply
referencing the attribute name, when referencing a method, you are required to prefix the method name with
adf.object
If you want to reference the same method from a validator, you have to use the source prefix.
source.<your_custom_method>
To access the next sequence value adf.object.nextVal("YOUR_SEQUENCE_NAME");
Of course, in practice you might create an EntityImpl helper method:
protected oracle.jbo.domain.Number nextVal(String sequenceName) {
SequenceImpl s = new SequenceImpl(sequenceName, getDBTransaction());
return s.getSequenceNumber();
}
-OR-
(new oracle.jbo.server.SequenceImpl("EMPLOYEES_SEQ",adf.object.getDBTransaction())).getSequenceNumber()
To access the Attribute Labels adf.object.hints.LastName.label
Access Session
Date and time
To access the current date and time adf.currentDate and adf.currentDateTime
Security Context
To get the username from security context adf.context.securityContext.userName
Groovy Expressions White Paper and Sample Code.
Entity Object Attribute and Raise error Groovy
The validation provides implicit object to access information contained within. Two of these information is oldValue and newValue, which gives you a handle to the value as it was before and after update.
.
If you want to raise a error message for high salary and low salary then you can use single validation to raise these error messages.
EX: in Create a attribute level script validation in the EO.
if(newValue > 10000)
{
adf.error.raise("EMPLOYEE_SALARY_IS_TOO_HIGH")
return false
}
if(newValue < 999)
{
adf.error.raise("EMPLOYEE_SALARY_IS_TOO_LOW")
return false
}
return true
Create these "EMPLOYEE_SALARY_IS_TOO_HIGH" and "EMPLOYEE_SALARY_IS_TOO_LOW" in the resource bundle.
Note: if you want raise a warning message use "adf.error.warn()".
Referencing custom methods in the EntityImpl class
If you have defined a method in your EntityImpl class, then this can be called as part of your expression for an attribute default:
adf.object.<your_custom_method>
Unlike when referencing an attribute of the entity object, which can be done by simply
referencing the attribute name, when referencing a method, you are required to prefix the method name with
adf.object
If you want to reference the same method from a validator, you have to use the source prefix.
source.<your_custom_method>
To access the next sequence value adf.object.nextVal("YOUR_SEQUENCE_NAME");
Of course, in practice you might create an EntityImpl helper method:
protected oracle.jbo.domain.Number nextVal(String sequenceName) {
SequenceImpl s = new SequenceImpl(sequenceName, getDBTransaction());
return s.getSequenceNumber();
}
-OR-
(new oracle.jbo.server.SequenceImpl("EMPLOYEES_SEQ",adf.object.getDBTransaction())).getSequenceNumber()
To access the Attribute Labels adf.object.hints.LastName.label
Access Session
adf.context.current.sessionScope.get('test')
ADFContext.getCurrent().getSessionScope().get("test");
Date and time
To access the current date and time adf.currentDate and adf.currentDateTime
Security Context
To get the username from security context adf.context.securityContext.userName
Groovy Expressions White Paper and Sample Code.
0 comments:
Post a Comment