2014-01-13 51 views
0

我在添加腳本時遇到問題。請找到如下使用extendedrenderkitservice添加腳本

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); 
    } 

我使用

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

我實際上是想基於類似事件(按鈕點擊等)生成Omniture PPRProcessing是JavaScript中的一種方法。該代碼完全運行,還打印「methodCall」作爲

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

我已經在執行頁面設置「afterPPRProcessing」的方法斷點但它不會在斷點處停止。

請幫我理解什麼可能是標記不生成的原因。編寫代碼時是否有任何錯誤?

在此先感謝

回答

1

爲了使用ExtendedRenderKitService調用任何javascript函數,函數調用必須存在於PPR響應中(響應是在請求的頁面URL被命中後產生)。在分析過程中,我發現PPR Response中缺少omniture調用「afterPPRProcessing」,其原因是在使用上述代碼添加Bean類的腳本後,出現了刷新整個頁面的代碼。以下代碼爲

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); 

這段代碼正在進行頁面刷新,而此方法用於捕獲PPR事件(開/關)。因此腳本不會被添加到ExtendedRenderKitService中的facesContext中。

註釋掉這段代碼後,PPR調用工作正常,我能夠生成矩陣。

感謝人們幫助

希望這可以幫助別人

0

有一對夫婦的原因,這些代碼可能無法正常工作:

  1. JavaScript方法afterPPRProcessing沒有定義
  2. JavaScript方法afterPPRProcessing不具有相同數量的的參數

通過解鎖你的chrome開發者控制檯並試試這個語法來確保你的javascript函數存在在瀏覽器中查看是否一切正常。

+0

我已經檢查並確認afterPPRProcessing方法在JavaScript中定義的,也有相同的參數。我試圖在控制檯中點擊該方法並生成標記。但是,當我試圖從java代碼中擊中標記不會生成。 – Jigar

+0

如果此函數試圖操作HTML DOM,則必須確保您使用的是ADF Javascript API,否則您將無法成功完成此操作。 –

+0

我正在使用ADF Javascript API。什麼可能是不產生的原因。任何幫助在此先感謝 – Jigar