Programmatically Accessing values from Resource Bundle
Showing posts with label programmatically. Show all posts
Showing posts with label programmatically. Show all posts
Tuesday, July 16, 2013
Monday, February 7, 2011
Setting datasource name programmatically for ADF Application
While working on an enterprise application for my client, i received a request from the client that data source name should not be hardcoded in the application and it should be configurable because client wants to deploy it more than one instance of application on the same server for different purposes like preview, production etc. So i googled it, and found excellent article 11g Dynamic JDBC Credentials for Model 1, Struts, Trinidad, and ADF Faces Rich Client
Here it is simplified version:
You will have to extend two following classes:
EnvInfoProvider
This is main interface and datasource name will be set in the implementation of this interace. You will have to implement following three methods:
Here it is simplified version:
You will have to extend two following classes:
- EnvInfoProvider
- DefaultSessionCookieFactory
EnvInfoProvider
This is main interface and datasource name will be set in the implementation of this interace. You will have to implement following three methods:
- public Object getInfo(String propName, Object object)
- public void modifyInitialContext(Object initialContext)
- public int getNumOfRetries()
public Object getInfo(String propName, Object object) {String myDataSourceName = "test"; // You can set it through your logicif (object instanceof Hashtable) {Hashtable connectionEnv = (Hashtable)object;System.out.println(connectionEnv.get(Configuration.JDBC_CONNECTION_NAME));String contextPath = (String)ADFContext.getCurrent().getSessionScope().get("contextPath");connectionEnv.put(Configuration.JDBC_DS_NAME,"java:comp/env/jdbc/"+myDataSourceName );}return null;}public void modifyInitialContext(Object initialContext) {}public int getNumOfRetries() {return 0;}
DefaultSessionCookieFactory
In order to configure custom implementation of EnvInfoProvider, you will have to extend DefaultSessionCookieFactory and override createSessionCookie method. Sample implementation is given below:
public SessionCookie createSessionCookie(String name,
String value,
ApplicationPool pool,
Properties properties) {
SessionCookie cookie = super.createSessionCookie(name, value, pool, properties);
Hashtable env = pool.getEnvironment();
env.remove(Configuration.JDBC_CONNECTION_NAME);
EnvInfoProvider provider = new MyEnvInfoProvider();
cookie.setEnvInfoProvider(provider);
return cookie;
}
Now last step is to configure this custom SessionCookieFactory. Open bc4j.xcfg of application module and add following element as a child of respected AppModuleConfig element
Tuesday, December 29, 2009
Programmatically Navigating to another page in adf / jsf
Here is the sample code which can be used to programmatically navigating to another page in jsf or adf
FacesContext fctx = FacesContext.getCurrentInstance();
Application application = fctx.getApplication();
NavigationHandler navHandler = application.getNavigationHandler();
navHandler.handleNavigation(fctx,null, "name of navigation case");
FacesContext fctx = FacesContext.getCurrentInstance();
Application application = fctx.getApplication();
NavigationHandler navHandler = application.getNavigationHandler();
navHandler.handleNavigation(fctx,null, "name of navigation case");
Doing some work before showing Popup in ADF
Here is the way to do any processing before calling popup. First of all create a method in backing bean and assign this to action of "commandButton" or "commandLink". Sample signature for you method is as follows:
public void myMethod()
{
/**
* Place your processing logic here and then call showPoup method
**/
showPopup(popupId);
}
Signature of showPopup is:
public static void showPopup(String popupId)
{
FacesContext context = FacesContext.getCurrentInstance();
ExtendedRenderKitService extRenderKitSrvc =
Service.getRenderKitService(context, ExtendedRenderKitService.class);
extRenderKitSrvc.addScript(context,
"AdfPage.PAGE.findComponent('" + popupId + "').show();");
}
public void myMethod()
{
/**
* Place your processing logic here and then call showPoup method
**/
showPopup(popupId);
}
Signature of showPopup is:
public static void showPopup(String popupId)
{
FacesContext context = FacesContext.getCurrentInstance();
ExtendedRenderKitService extRenderKitSrvc =
Service.getRenderKitService(context, ExtendedRenderKitService.class);
extRenderKitSrvc.addScript(context,
"AdfPage.PAGE.findComponent('" + popupId + "').show();");
}
Subscribe to:
Posts (Atom)