Monday, May 30, 2011

Changing Portlet Persistent Store from File to Database in Oracle Webcenter

Share this Post

Last week i got a recommendation from Oracle support on some issues in our environment to change portlet persistent store from file to database. By default portlets store their state in file at OS level it is recommended for high availability and specially in a cluster environment to use database as a persistence store.

You can verify the portlets current persistent on INFO page of portlet which has a the following URL syntax


As you can see in following screen shot the persistent store is set to File.

Changing Persistent store

It is a 3 step process
  1. Change setting in web.xml file 
  2. Run Persistence migration utility
  3. Change meta-data-storage settings in adf-config.xml
Step 1:
Add a environment entry in web.xml to tell portlet to use database as persistent store

Step 2:

Run Persistence migration utility as oracle os user make sure you set the JAVA_HOME variable to correct Java home.

$java  -classpath /u01/Oracle/Middleware/Oracle_WC1/webcenter/modules/oracle.portlet.server_11.1.1/oracle-portlet-api.jar:/u01/Oracle/Middleware/Oracle_WC1/webcenter/modules/oracle.portlet.server_11.1.1/wsrp-container.jar:/u01/Oracle/Middleware/wlserver_10.3/server/lib/ojdbc6.jar oracle.portlet.server.containerimpl.PersistenceMigrationTool -sourceType file -destType db -sourcePath /u01/Oracle/Middleware/Oracle_WC1/portal/portletdata -destUsername dev_portlet -destPassword myPassword -destDatabase mydatabase:1521:mySID -debug

Step 3:
Change metadata-store to database jndi as shown in the screen shot

Test the new changes by going to the Portlet info page

Verify the portlet appearance in MDS repository in EM FMW

Register the Portlet again, delete the portlet from webcenter page and add again

Have a nice day,
Zeeshan Baig

Sunday, May 29, 2011

How to execute Javascript in Java in Oracle ADF

Share this Post

A quick code snippet how to execute Javascript in java in Oracle ADF.

import javax.faces.context.FacesContext;
import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;

FacesContext fctx = FacesContext.getCurrentInstance();
ExtendedRenderKitService erks =
Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
String myJavaScriptCode = "alert( "+"Hello World"+");";
erks.addScript(fctx, myJavaScriptCode );

Have a nice day,
Zeeshan Baig

How to get the Page Id in Oracle ADF

Share this Post

Another quicky today. How to get the page id of current page in Java.

lets have a quick look

//get the Context
FacesContext fctx = FacesContext.getCurrentInstance();

//get the Page id in String
String viewId = fctx.getViewRoot().getViewId();

//Display Id in Message
FacesMessage message = new FacesMessage("Hello Page no "+viewId);

Have a nice day,
Zeeshan Baig

Monday, May 16, 2011

How to run Java code on every page load in Oracle ADF

Share this Post

Still i am not able to find peace in my new place to record YouTube videos :) but i hope soon that is coming too.

I experienced a use case where i have to embedded the java script code in every page of the application. One way to do is to use af:resource component on every page which is kinda work to do.

A simpler solution that fits my use case was to use the "Page Phase Listener" which allows to write a global code on every page load. Oracle docs has a overview of phase listeners in great detail. I call the required javascript using java in page phase listener class.

Here are the steps to write code that runs globally on page load. to make it simple i just wrote a method to display a current page name on page load.

 1. Write a class that implements PagePhaseListener Interface as shown in the slide.

 2. Override method as follows.

    public void afterPhase(PagePhaseEvent pagePhaseEvent) {
        if (pagePhaseEvent.getPhaseId() == Lifecycle.PREPARE_RENDER_ID) {
            FacesContext fctx = FacesContext.getCurrentInstance();
            String viewId = fctx.getViewRoot().getViewId();
            FacesMessage message = new FacesMessage("Hello Page no " + viewId);
            fctx.addMessage(null, message);

3. Register your listener in /META-INF/adf-settings.xml file ( if file doesn't exists create a simple XML file) as follows


5. Run your page the output will be as shown in the slide.

Download the example

Hope you find it useful.

Zeeshan Baig

Sunday, May 1, 2011

How to load Javascript and CSS files with dynamic URL

Share this Post

It is good practice to place all sharable javascript and css files on server so they can take the benefit of web cache. In our environment we have virtual directories on IIS server where we have placed all JS, css and images. Those files are sharable between different apps in 3 different environment i.e development, testing and  production.

Here is the quick tip how to load these files dynamically from all different servers without code changing in JSF page.

Another way to load scripts in JSF page is by using trh:script tags

Note that Libs, js and css are directories on webservers

Hope you find it useful

Happy Jdeveloping,
Zeeshan Baig