Monday, November 17, 2014

Show status indicator for long running method calls

ADF status indicator provides a way to notify users of a long running process on the page, but does not serve the purpose if the long running process starts before the page gets loaded. For example, there is a task flow that has a method call as its default activity. This method calls a SOAP service and hence takes a good amount of time to complete its execution. The next activity on the task flow is a web page, which only gets loaded when the method call is completed. So, if we add a status indicator on the page, it will not consider the execution time before the loading of page and also there is no way to directly use status indicator on top of a method call.


To notify users of a long running process in such scenarios, replace the method call activity on task flow with a view activity. This view activity will represent a page, which will execute the method call on page load event and will use status indicator to notify the user.


<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <jsp:directive.page contentType="text/html;charset=UTF-8"/>
  <f:view>
    <af:document id="d1">
      <af:messages id="m1"/>
<!-- Calling method on page load -->
      <af:serverListener type="onloadEvent"
                         method="#{backingBeanScope.initBean.callMethod}"/>
      <af:clientListener type="load" method="triggerOnLoad"/>
      <af:resource type="javascript">
        function triggerOnLoad(event)
        {
          AdfCustomEvent.queue(event.getSource(), "onloadEvent", {},false);
          return true;
        }
      </af:resource>
      <af:form id="f1">
<!-- Displaying status indicator in the middle of the page -->
        <af:panelStretchLayout id="psl1" startWidth="33%" endWidth="33%"
                                   topHeight="33%" bottomHeight="33%">
          <f:facet name="bottom"/>
          <f:facet name="center">
            <af:panelGroupLayout id="pglsi1" layout="vertical"
                                 styleClass="AFStretchWidth" halign="center"
                                 inlineStyle="font-size:medium; font-family:Arial, Helvetica, sans-serif;">             
              <af:outputText value="Loading ......" id="ot1"/>
              <af:spacer width="10" height="10" id="s2"/>
              <af:statusIndicator id="si1"/>              
            </af:panelGroupLayout> 
          </f:facet>
          <f:facet name="start">
            <af:panelGroupLayout id="pgl2"/>
          </f:facet>
          <f:facet name="end">
            <af:panelGroupLayout id="pgl3"/>
          </f:facet>
          <f:facet name="top">
            <af:panelGroupLayout id="pgl4"/>
          </f:facet>
        </af:panelStretchLayout>
      </af:form>
    </af:document>
  </f:view>
</jsp:root>

Now, you will see a status indicator during the wait time till the page loads completely



<< A Request >>
  Please contribute in making this world a better place to live in by adopting a pet from your nearest pet shelter (btw cats are my favourite :-) )
<< Thank You >>

No comments:

Post a Comment