Wednesday, March 12, 2014

Using af:poll for long running taskflows

I recently was asked a question about how taskflows are loaded in a WebCenter page, and In remembered a previous implementation where we encountered some issues with long loading pages and needed to speed them up.


As you might already know, in a normal ADF page containing multiple taskflows, each taskflows needs to be initialized and their initial views created before the overall page can be rendered. what this means is that if you have a long running taskflow, it will afect the entire page’s performance.


You can manage the partial page refresh and do things like Lazy Loading for subsequent request, but the initial one needs to have a view object for the page to render.


With this in mind we looked at the different tasksflow and found one in particular that was taking a long time to load, removing the tasksflow made the whole page performed 4x faster. This is where we needed to get creative,


We needed to create a view object for the tasksflow even if the over all results (a webservice query that was gathering information from the EBS HR records) was not ready.


For this we used the af:poll component. the idea being that the will be an initial request to the web service and the pool will monitor the results (stored in a managed bean) if the results where not present yet, we use a af:switcher to print a simple message (“Loading...”). hence creating the view object and allowing the page to load.


Once the results are loaded, we simply set the value of the poll to “-1” disabling the refresh

This is a sample code of how this might work:


<af:panelGroupLayout id="pgl1" layout="vertical" halign="center" partialTriggers="loadData">
         <af:poll id="loadData" interval="#{pageFlowScope.myESSDetailsManagedBean.hasloaded == 0 ? 1000 : -1}"
                   pollListener="#{pageFlowScope.myESSDetailsManagedBean.loadLinks}"
                   immediate="true" rendered="true"/>
         <af:spacer width="10" height="20" id="s1"/>
         <af:switcher id="s2"
         facetName="#{pageFlowScope.myESSDetailsManagedBean.hasloaded == 0? 'Loading':
                            pageFlowScope.myESSDetailsManagedBean.errorCode eq '1'?'GeneralError':
                            pageFlowScope.myESSDetailsManagedBean.errorCode eq '2'? 'NoAccess':
                            'Ok'}">
            <f:facet name="GeneralError">
               <af:outputText value="Error contacting the EBS, Please try again later"
                                     id="ot2"/>
            </f:facet>
            <f:facet name="NoAccess">
               <af:group id="g1">
                  <af:outputText value="You don't have access to the ESS module in EBS"
                                        id="ot1"/>
               </af:group>
            </f:facet>
            <f:facet name="Loading">
               <af:group id="g2">
                  <af:outputText value="Loading ...."
                                        id="ot3"/>
               </af:group>
            </f:facet>
            <f:facet name="Ok">
               <af:panelGroupLayout id="pgl2" layout="vertical" halign="center">

                  <af:outputText value="THIS IS WHERE THE RESULTS ARE DISPLAYED"
                                        id="ot1"/>
                  
                  <af:goLink text="Your current leave balance is #{pageFlowScope.myESSDetailsManagedBean.leaveBalance}"
                                        id="gl6"
                                        destination="#{pageFlowScope.myESSDetailsManagedBean.leaveBalanceFullURL}"
                                        targetFrame="_blank"
                                        rendered="#{pageFlowScope.myESSDetailsManagedBean.leaveBalance ne ''}"/>
                     
                        <af:goLink text="Manage Your Leave" id="gl7"
                                        destination="#{pageFlowScope.myESSDetailsManagedBean.leaveBalanceFullURL}"
                                        targetFrame="_blank"
                                        rendered="#{pageFlowScope.myESSDetailsManagedBean.leaveBalance eq ''}"/>
                  
                     <af:spacer width="10" height="10" id="s5"/>
      
         
               </af:panelGroupLayout>
            </f:facet>
         </af:switcher>
      </af:panelGroupLayout>

No comments: