Tuesday, June 8, 2010

Get Application Module Reference Programmatically in ADF 11.1.1.2.0

Getting Application Module reference using datacontrol name:

We can write this piece of code in our managed Bean. Application Module has direct visibility to view and entity so we may need to access Application Module from our user interface.We can pass data control name as string to getApplicationModuleForDataControl function

  1. public static ApplicationModule getApplicationModuleForDataControl(String name) {
  2. System.out.println("#{data." + name + ".dataProvider}");
  3. return(ApplicationModule)resolveExpression("#{data." + name + ".dataProvider}");}

Where resolveExpression()

is defined as
//Argument expression is #{data.ProjectAppModuleDataControl.dataProvider} where ProjectAppModuleDataControl is data control name
  1. public static Object resolveExpression( String expression){ //A FacesContext instance is associated with a particular request at the beginning of request processing, by a call to the getFacesContext() method of the FacesContextFactory instance associated with the current web application
  2. FacesContext ctx = getFacesContext() ; //Getting Application Reference
  3. Application app = ctx. getApplication() ; //createValueBinding(String expr) converts String expr to Value Binding expression which is used to bind UI Components i.e.(data. ProjectAppModuleDataControl.dataProvider) or their values to external data source
  4. ValueBinding bind = app. createValueBinding (expression); //Getting Value from ValueBinding Expression
  5. return bind. getValue (ctx); }

1 comment:

  1. Here I have used getFacesContext() function which is available in JSFUtils.java. means if you import the .java file then getFacesContext will be referred automatically but if you don't want to import entire java file then getFacesContext can be defined as below


    public static FacesContext getFacesContext() {
    return FacesContext.getCurrentInstance();
    }

    ReplyDelete