Showing posts with label Groovy. Show all posts
Showing posts with label Groovy. Show all posts

09 July, 2012

Add Validation at Runtime in ADF


An user request the below requirement.
He want to change validation condition in specific attribute at Entity Object at runtime.

For example there is a maximum of employee salary which can be changed at runtime, therefore the user doesn't want the maximum salary of employee to be fixed.

So I will create a new method for setting Validation Expression at runtime using Groovy.

   public void addExpressionValidator(AttributeDef attributeDef, String groovyExpression, String errorMessage) {  
     //create new ExpressionValidator  
     JboExpressionValidator jboExpressionValidator = new JboExpressionValidator(false, groovyExpression);  
   
     //Set an error message  
     jboExpressionValidator.setErrorMsgId(errorMessage);  
   
     //adding the validator to the attribute  
     ((AttributeDefImpl)attributeDef).addValidator(jboExpressionValidator);  
   
   }  

26 June, 2012

ADF : Get Current Logged User Name

Sometime we need getting current authenticated user name in ADF application.
To get user name we can do it using three ways

1- Using Groovy 
We can set default expression in view object attribute as below
adf.context.securityContext.getUserPrincipal().getName() 
or
adf.context.securityContext.getUserName() 

2- Java Code
You can get User Name in Java code also using the following code.

     ADFContext adfCtx = ADFContext.getCurrent();  
     SecurityContext secCntx = adfCtx.getSecurityContext();  
     String user = secCntx.getUserPrincipal().getName();  
     String _user = secCntx.getUserName();  

3-Expression Lnagugae
You can bind ADF Faces componenets with the following EL to get logged User Name.

 #{securityContext.userName}  

Thanks

15 September, 2011

Default Value for View Object Rows Attributes

Hi all,
Introduction
As usual in all programming tools we need to set default values for columns.
>>In oracle database we can do that by DDL
ALTER TABLE Table_name MODIFY(column_name  DEFAULT default_value);
>>In oracle forms tool we can do that by setting initial value of item in block.

So I will present how to set deafult value of attribute in VO at ADF.
We can do that by 3 ways
1-Using a Groovy expression
2-Getter of attribute
3-Override view object create() method

01 August, 2011

Get sequence next value in ADF


I will present how to use ADF BC to get next value of sequence.

1- Creating Method 

We can create generic method that I will pass to it sequence name and it will return next value.


As we noticed in previous code that I use SequenceImpl to get sequence value.

15 July, 2011

Summary Functions in ADF Business Component

SA,
I will present how to create summary function (sum, count, min, max and avg)   in ADF BC and clarify how these can be used at Entity level and View level. That is done using Groovy syntax.
I will use scott schema (EMP and DEPT Tables)

Entity Level
We will create example to get employees count in every departments.
First, we need to have association between entities representing master-detail relationship and the destination accessor name is what we are going to use in our groovy
Syntax: <Accessor>.aggregate_function(Groovyexpression)

ADF : Scope Variables

Oracle ADF uses many variables and each variable has a scope. There are five scopes in ADF (Application, Request, Session, View and PageFl...