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
- public static ApplicationModule getApplicationModuleForDataControl(String name) {
- System.out.println("#{data." + name + ".dataProvider}");
- return(ApplicationModule)resolveExpression("#{data." + name + ".dataProvider}");}
Where resolveExpression()
is defined as//Argument expression is #{data.ProjectAppModuleDataControl.dataProvider} where ProjectAppModuleDataControl is data control name
- 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
- FacesContext ctx = getFacesContext() ; //Getting Application Reference
- 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
- ValueBinding bind = app. createValueBinding (expression); //Getting Value from ValueBinding Expression
- return bind. getValue (ctx); }
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
ReplyDeletepublic static FacesContext getFacesContext() {
return FacesContext.getCurrentInstance();
}