Saturday, September 19, 2015

ADF application Integration with Oracle Documents Cloud Service

Here,

You need to call the AppLink Resource via REST. This gives you a URL which you can drop into an iFrame.

You need to perform some javascript handling that needs to be done when you load an applink url in an iframe.  The appLinkReady event must be handled. In the following code snippets, this was done in a JSP file which is called from the application. Here's the sample JSP file


===========================================================

<%@ page contentType="text/html;charset=UTF-8"%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>view</title>
        <script>
            function OnMessage(evt) {
                /*Created By Sheka 14042015, Attach cloud document to my inline frame*/
                if (evt.data.message === 'appLinkReady') {
                  var iframe = document.getElementById('if1');
                  var iframewindow = iframe.contentWindow ? iframe.contentWindow : iframe.contentDocument.defaultView;
                  var dAppLinkRefreshToken = document.getElementById('refreshTokenField').value;
                  var dAppLinkAccessToken = document.getElementById('accessTokenField').value;
                  var dAppLinkRoleName = document.getElementById('roleField').value;
                  var embedPreview = true;
               
                  var msg = {
                      message : 'setAppLinkTokens', appLinkRefreshToken : dAppLinkRefreshToken, appLinkAccessToken : dAppLinkAccessToken, appLinkRoleName : dAppLinkRoleName, embedPreview : embedPreview
                  };
                  iframewindow.postMessage(msg, '*');
              }
            }
            function assignMessageListener(){
                window.addEventListener('message', OnMessage, false);
            }
        </script>
    </head>
    <body onload="assignMessageListener();">
    <iframe id="if1" src="${sessionScope.frameSource}" width="100%" height="700px"></iframe>
    <input type="hidden" id="frameSourceField" value="${sessionScope.frameSource}" size="500"/>
    <input type="hidden" id="refreshTokenField" value="${sessionScope.refreshToken}" size="500"/>
    <input type="hidden" id="accessTokenField" value="${sessionScope.accessToken}" size="500"/>
    <input type="hidden" id="roleField" value="${sessionScope.role}" size="500"/>
 
    </body>
</html>

==================================================================

In your ADF page fragment , add:


<af:inlineFrame id="mainf" source="/view.jsp"  styleClass="AFStretchWidth"

                                inlineStyle="height:800px"></af:inlineFrame>


===================================================================

Finally, in the managed bean, add:

 public String viewFileAction() {
        FacesContext ctx = getFacesContext();
        HttpSession session = (HttpSession)ctx.getExternalContext().getSession(true);              
        AppLink al = CreateFileAppLink.getFileUrl(getFileId());
              System.out.println(al);
              setFrameSource(al.getAppLinkUrl());
              setRefreshToken(al.getRefreshToken());
              setAccessToken(al.getAccessToken());
              setRole(al.getRole());            
        session.setAttribute("frameSource", getFrameSource());
        session.setAttribute("refreshToken", getRefreshToken());
        session.setAttribute("accessToken", getAccessToken());
        session.setAttribute("role", getRole());
return null;

}

===================================================================


Hope this helps :)

1 comment:

  1. Hi,

    Nice article, exactly what I was looking for, but when I implemented the same document in the frame keeps on loading. any idea on fixing this.

    Thanks
    Apoorv

    ReplyDelete