Question

I am facing a problem in adding script. Please find my code as below

    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExtendedRenderKitService extendRenderKitService = Service.
        getRenderKitService(facesContext, ExtendedRenderKitService.class);
    try {
        String methodCall = "afterPPRProcessing('" + journeyId + "',new Array (" + dynamicParams + "))";
        System.out.println( "methodCall::" + methodCall);
        extendRenderKitService.addScript(facesContext, methodCall);
    } catch (Exception ex) {
        System.out.println("exception while PPR processing ", ex);
    }

I am using

  1. javax.faces.context.FacesContext;
  2. org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
  3. org.apache.myfaces.trinidad.util.Service;

I actually want to generate Omniture based on events like (Button click etc.) afterPPRProcessing is a method in javascript. The code perfectly runs and also prints "methodCall" as

methodCall::afterPPRProcessing('abc',new Array ('xyz','pqr'))

I have set the breakpoint in 'afterPPRProcessing' method while executing page but it doesn't stops at the breakpoint.

Please help me to understand what might be the reason for tagging not generated. Is there any mistake done while writing code.

Thanks in advance

Was it helpful?

Solution

In order to make a call to any javascript function using ExtendedRenderKitService, The function call has to be there in PPR response(response which is generated once the requested page url is hit). During analysis I found that omniture call "afterPPRProcessing" was missing in PPR Response and the reason for it is that after adding script from Bean class using above mentioned code there was a code to refresh entire page.Below is the code

    FacesContext context = FacesContext.getCurrentInstance();
    String viewId = context.getViewRoot().getViewId();
    ViewHandler handler = context.getApplication().getViewHandler();
    UIViewRoot root = handler.createView(context, viewId);
    root.setViewId(viewId);
    context.setViewRoot(root);

This piece of code is doing a page refresh while this method is for capturing PPR event (On/ Off). As a result the script is not getting added to facesContext in ExtendedRenderKitService.

After commenting out this code the PPR call is working fine and I am able to generate matrix.

Thanks to people for helping

Hope this might help others

OTHER TIPS

There are a couple of reasons this code might not work:

  1. The Javascript Method afterPPRProcessing is not defined
  2. The Javascript Method afterPPRProcessing doesn't have the same number of arguments

Make sure your javascript function exist by firing your chrome developer console and try this syntax in your browser to see if everything is right.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top