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…… 🙂

valueChangeListener is not working on checkbox or SelectOneChoice in Oracle ADF

Requirment-valueChangeListener is not working on checkbox or SelectOneChoice in Oracle ADF

Solution-While working in ADF project, normally we have checkbox or SelectOneChoice , radio buttons (af:selectOneRadio) and list of values ie., LOVs etc.

when we wrote value change listener on it. everything seems to be perfect. but sometimes ,weird things happened in this world. our valueChangeListener is not getting called.It happend , if you using iterator or some varible in it. developer spent lot of times spending on it, why it is not called when everything seems to be correct.

You just need to do one change,.in your valueChangeListener add below code as first line.

valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());

Thats it. It should work now.

Now let check out, what we have done here as by oracle doc.
processUpdates

public abstract void processUpdates(javax.faces.context.FacesContext context)- Perform the component tree processing required by the Update Model Values phase of the request processing lifecycle for all facets of this component, all children of this component, and this component itself, as follows.

If the rendered property of this UIComponent is false, skip further processing.
Call the processUpdates() method of all facets and children of this UIComponent, in the order determined by a call to getFacetsAndChildren().

Parameters:
context – FacesContext for the request we are processing
Throws:
java.lang.NullPointerException – if context is null


It process the component value in update model value phase of lifecycle.

Happy coding with Vinay in Techartifact ….. 🙂

Method call between train flow in ADF | Techartifact

Requirment – To call the method between the train flow in ADF.

For this we need to use outcome property of view. You need to perform following activity.

Wildcard control flow leading to first activity of the train stop, CollateSurveyAnswers.

1. Drag and drop a wildcard flow in task flow.
2. Drag and drop a method call in the taskflow
3. create a navigation case between Wildcard control flow to method call activity.

4. The navigation case name between Wildcard control flow to method call activity is set to outcome property of the view from which you want to call
the method before navigating to that view. For example you are having view1, view2, view3 and view4 in train taskflow.
You want to execute method call before view3.Then you should set the outcome property of view3 to navigation case between Wildcard control flow to method call activity.

5. Create a navigation case from method call to that view.

Note:
The train stop outcome element is used only if an activity such as a method call activity or router is placed prior to the view activity train stop. The element allows you to specify a custom outcome that results in navigation to the train stop.

Enjoy Coding with Techartifact..