Call method on page load of JSFF (JSF fragment) in Oracle ADF

Requirement – Calling a method on page load at render response time for jsf fragment in oracle ADF

Solution – Alright. Few of ADF guys will say, use pagePhaseListener is answer. Well , you are not right .pagePhaseListener is work only in jspx , not in jsff. 🙁 . As i already written about
pagePhaseListener in jspx here – invoke method on page load for jspx

Ok, we will use regionController,We will create a bean which implement regionController.

Create a bean which implements RegionController.

package com.techartifact.hte.bean.audittrailall;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
import oracle.adf.model.RegionBinding;
import oracle.adf.model.RegionContext;
import oracle.adf.model.RegionController;
import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;

public class AuditTrailAllAppPhaseListener implements RegionController{
    public AuditTrailAllAppPhaseListener() {
    public boolean refreshRegion(RegionContext regionContext)   // you need to override refresh region method.
        int refreshFlag= regionContext.getRefreshFlag();
        FacesContext fctx = FacesContext.getCurrentInstance();
        //check internal request parameter
        Map requestMap = fctx.getExternalContext().getRequestMap();
        PhaseId currentPhase=(PhaseId)requestMap.get("oracle.adfinternal.view.faces.lifecycle.CURRENT_PHASE_ID");   
        if(currentPhase.getOrdinal()==PhaseId.RENDER_RESPONSE.getOrdinal())   // write custom logic of correct lifecycle phase.
            Object showPrintableBehavior =
            if (showPrintableBehavior != null)
                if (Boolean.TRUE == showPrintableBehavior) 
                ExtendedRenderKitService erks = null;
                erks =
                Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
                //invoke JavaScript from the server
                erks.addScript(fctx, "window.print();");
                erks.addScript(fctx, "window.close();");
    return false;
    public boolean validateRegion(RegionContext regionContext) 
        return false;
    public boolean isRegionViewable(RegionContext regionContext) 
     return regionContext.getRegionBinding().isViewable();
        public String getName() 
        return null;

Ok , then you need to register this class file in jsff page definitoon file using controllerClass like below –

<?xml version="1.0" encoding="UTF-8" ?>
<pageDefinition xmlns=""
                version="" id="audit_trail_allPageDef"

That is all .Now run your can write your java code on page code,in my case i call some javascript..

Happy coding with Vinay kumar in techartifact…… 🙂


I am an Oracle ACE in Oracle ADF/Webcenter. Sr Java Consultant-working on Java/J2EE/Oracle ADF/Webcenter Portal/ content and Hibernate for several years. I'm an active member of the OTN JDeveloper/Webcenter forum. Passionate about learning new technologies. I am here to share my knowledge. Give your views and suggestion on [email protected] .

More Posts - Website

Follow Me:
TwitterLinkedInGoogle PlusYouTube