Friday, April 8, 2011

Initializing your Fusion Web Application Parameters at startup

If you need to initialize specific business data during application start up,this post is for you.

Download

You can download the sample workspace from here.
[Runs with Oracle JDeveloper 11g R1 PS3 + HR Schema]

A glance at the implementation

This example make use of a custom javax.servlet.ServletContextListener for performing the application initialization during deployment. Please see 'view.ContextInitializer' class in the attached sample workspace, which act as the ServletContextListener in this example. btw, check out this post How to work with ServletContextListener if you not familiar with this approach.

This example invokes ApplicationModule and populates the ServletContext attributes from the custom ServletContextListener's ContextInitializer::contextInitialized(...) method. Please note that ADFContext.getCurrent().getApplicationScope() in a web app refers the ServletContext. It means that whatever you set to ServletContext, can be retrieved later by calling ADFContext::getApplicationScope() from the Model layer. You can use EL #{applicationScope.someVariable} if you need to refer ServletContext attributes from the UI.

The above example initializes a default DepartmentId during application start up and the same is used in the the Employees View Object query using groovy expression to get the employees (default DepartmentId is configured as context-param in the web.xml)

No comments: