Sep 22, 2011

ADF-GROOVY : Use Java classes in groovy expressions

Today I will discuss about how you can use Java classes in groovy expressions. In this blog I will show you how you can access Private class fields, Protected class fields, Static class fields and Enums.



Download Application: (Developed using Jdeveloper 11g R2)
Groovy Example Application


Here is the snippet of Bean.java
   1: package com.tanvir.groovy.model.views;
   2:  
   3: public class Bean {
   4:     private String privateJobId = "FI_ACCOUNT";
   5:     protected String protectedJobId = "IT_PROG";
   6:     public static String STATIC_JOB_ID = "PU_CLERK";
   7:     
   8:     public Bean() {
   9:         super();
  10:     }
  11:  
  12:     public void setPrivateJobId(String privateJobId) {
  13:         this.privateJobId = privateJobId;
  14:     }
  15:  
  16:     public String getPrivateJobId() {
  17:         return privateJobId;
  18:     }
  19:  
  20:     public void setProtectedJobId(String protectedJobId) {
  21:         this.protectedJobId = protectedJobId;
  22:     }
  23:  
  24:     public String getProtectedJobId() {
  25:         return protectedJobId;
  26:     }
  27: }

Here is the snippet of JobIdEnum.java


   1: package com.tanvir.groovy.model.utils;
   2:  
   3: public enum JobIdEnum {
   4:     ST_CLERK("ST_CLERK"),
   5:     SA_REP("SA_REP");
   6:     
   7:     private String jobId;
   8:     
   9:     private JobIdEnum(String jobId) {
  10:         this.jobId = jobId;
  11:     }
  12:  
  13:     public String toString() {
  14:         return jobId;
  15:     }
  16: }

I have created one view criteria for each case and used bind variable to apply the groovy expression. Following are the groovy expressions for each case.


1. How to access Private class field (used in view criteria PrivateBeanVarVC)

SNAGHTML868ce6

2. How to access Protected class field (used in view criteria ProtectedBeanVarVC)

SNAGHTML8a5830

3. How to access Static class field (used in view criteria StaticVarVC)

SNAGHTML8bb78e

4. How to access Enum (used in EnumVarVC)

SNAGHTML8ca22a

Runtime:

image

Changing the “Saved Search” criteria will give you results for other cases.

1 comment:

laisajacquetta said...

The Hard Rock Hotel and Casino - JTM Hub
Book your 영주 출장샵 stay at 동두천 출장마사지 the Hard Rock Hotel and Casino in 남양주 출장안마 Las Vegas, Nevada. 전주 출장마사지 Enjoy 24/7 창원 출장안마 friendly customer service and online booking.