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() {
        super();
    }
    
    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 =
            requestMap.get("oracle.adfinternal.view.faces.el.PrintablePage");
            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();");
                    
                }
           }
                regionContext.getRegionBinding().refresh(refreshFlag);
        }
    return false;
    }
     
    public boolean validateRegion(RegionContext regionContext) 
    {
        regionContext.getRegionBinding().validate();
        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="http://xmlns.oracle.com/adfm/uimodel"
                version="11.1.1.61.92" id="audit_trail_allPageDef"
                ControllerClass="com.techartifact.hte.bean.audittrailall.AuditTrailAllAppPhaseListener"
                Package="com.techartifact.hte.pages.audittrailall">
  <parameters/>
  <executables>

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

Happy coding with Vinay kumar in techartifact…… 🙂

Why we can’t override the static method? or Overriding Vs Hiding

Can I override a static method? – No you cant

Many people have heard that you can’t override a static method. This is true – you can’t. However it is possible to write code like this:

class test {
    public static void method() {
        System.out.println("in test");
    }
}

class example extends test{
    public static void method() {
        System.out.println("in example");
    }
}

This compiles and runs just fine. Isn’t it an example of a static method overriding another static method? The answer is no – it’s an example of a static method hiding another static method. If you try to override a static method, the compiler doesn’t actually stop you – it just doesn’t do what you think it does.

lets try it

Briefly, when you override a method, you still get the benefits of run-time polymorphism, and when you hide, you don’t. So what does that mean? Take a look at this code:

class test{
    public static void classMethod() {
        System.out.println("classMethod() in test");
    }

    public void instanceMethod() {
        System.out.println("instanceMethod() in test");
    }
}

class example extends test {
    public static void classMethod() {
        System.out.println("classMethod() in example");
    }

    public void instanceMethod() {
        System.out.println("instanceMethod() in example");
    }
}
 
class Test {
    public static void main(String[] args) {
        test f = new example();
        f.instanceMethod();
        f.classMethod();
    }
}



If you run this, the output is

instanceMethod() in example
classMethod() in test

Now we should understand what is overriding and hiding-

Overriding
An instance method overrides all accessible instance methods with the same signature in superclasses [JLS 8.4.8.1], enabling dynamic dispatch; in other words, the VM chooses which overriding to invoke based on an instance’s run-time type [JLS 15.12.4.4]. Overriding is fundamental to object-oriented programming and is the only form of name reuse that is not generally discouraged:

class Base {
    public void f() { }
}

class Derived extends Base {
    public void f() { } // overrrides Base.f()
}

Hiding
A field, static method, or member type hides all accessible fields, static methods, or member types, respectively, with the same name (or, for methods, signature) in supertypes. Hiding a member prevents it from being inherited.

class Base {
    public static void f() { }
}

class Derived extends Base {
    public static void f() { } // hides Base.f()
}

Instance methods and class methods have this important difference in behavior, we use different terms – “overriding” for instance methods and “hiding” for class methods – to distinguish between the two cases. And when we say you can’t override a static method, what that means is that even if you write code that looks like it’s overriding a static method (like the first test and example at the top of this page) – it won’t behave like an overridden method.

Executing AmImpl method in managed bean in Oracle ADF | Techartifact

Requirement – Executing AmImpl method in managed bean in Oracle ADF

We can execute the AmImpl method in managed bean using following method.We can get the bindings object.

        BindingContainer bindings = getBindings();
        int checkListID =  ((BigDecimal)valueChangeEvent.getNewValue()).intValue();
       OperationBinding refreshChecklist = bindings.getOperationBinding("checklistQuery");//checklistQuery is method name in Applicationmoduleimpl file
        refreshChecklist.getParamsMap().put("checklistId", checkListID);  // checklistId is parameter for that method.


happy coding with techartifact