Wednesday Jul 18, 2012

How to access published ADFdi enabled excel workbook from ADF Library jar

We generally tend to create multiple applications and re-use them in one main application by adding them as ADF Library jars.Applications with ADF Desktop Integration support added to ViewController can also be re-used.

This blog is about how to access workbooks in ADF Library jar from a different application(which consumes ADF Library Jar).

Assumption : Let's assume that a simple ADF application(TestApp) is created with Dept and Emp as entities and added as Master Form Detail Table in jspx.Also an ADFdi enabled excel workbook is created to simulate DeptView and EmpView as Master Form Detail Table.Publish the workbook(PBook1.xlsx) and store it in ViewController/public_html/excel/ folder and check for the working of published workbook by re-deploying the application.

Now,let's proceed to the steps to be done before deploying ViewController as ADF Library jar.

Open web.xml in ViewController->Web Content->WEB-INF of TestApp, in Filters tab, check for adfBindings and adfdiExcelDownload filters. If not present add by referring this ADFdi guide.

Create a new deployment profile for ViewController by right-click ViewController and Deploy->New Deployment profile. Select ADF Library Jar File as Profile Type and give a profile name like TestAppLibJar

Create a new custom application(ClientApp) with ADF ViewController as project.

Create a FileSystemConnection to import the deployed library jar of TestApp as below:
In Resource Pallete, open New File System Connection, give Connection Name as TestAppConn and for DirectoryPath browse and select the deploy folder inside ViewController of TestApp application.

FSConnection

Select ViewController of ClientApp, expand the TestAppConn(File System Connection) created, select TestAppLibJar, right-click and Add to Project. In Confirmation dialog, click on Add Library,

AddJar

In ViewController add ADF Desktop Integration support by right-click ViewController->Project Properties->Features, click on + sign and move ADF Desktop Integration from Available to Selected.

ADFdiScope

Add ADF Library Web Application Support into ViewController of ClientApp by right-click ViewController->Project Properties->ADF View, select Enable ADF Library WebApp Support checkbox.

ADFLibWebAppSup

Open web.xml and check for the correct ordering of ADFLibraryFilter and adfdiExcelDownload filter. Make sure adfdiExcelDownload filter is above ADFLibraryFilter.

webxml_clientApp

Add Initialization Parameter for ADFLibraryFilter with Name 'include-extension-list' and Value 'png,jpg,jpeg,gif,js,css,htm,html,xlsx' as shown in above pic.

Now we will create a jspx page and add Go link with Text 'Download Excel' and Destination '/excel/PBook1.xlsx'

DloadPage

Run the jspx page and click on Download Excel link. Click on Open, and give yes in Login dialog. There we go, here is our published workbook.

FinalPBook

Friday Mar 02, 2012

Refreshing One Column based on the value of Another Column in ADFdi Table

When using ADF Desktop Integration, quite frequently, we get into a situation where we would like to refresh one column based on the value of another column. In ADF Faces, we can achieve this by setting the autoSubmit property and partialTriggers property for the corresponding columns.

However, in ADFdi, we do not have such option. Though we can achieve this by using LOVs and Dependent LOVs. But, in some scenarios we would like to achieve this when using an Input Text Component.

In this article, we will simulate this Auto Refresh functionality in a ADFdi Table.

Note : Since we would be using VBA code to achieve this, we can use this only on the Macro Enabled Excel Workbooks.

Let us assume that we have a View Object based on the Emp table. We could take an example of having a transient attribute in the VO, that gives the sum of Salary and Commission attributes.

SalPlusComm.jpg



In the above example, we've added a new transient attribute (SalPlusComm) to the EmpVO, that would give the sum of Sal and Comm attributes. Since we need this attribute to get refreshed when either Sal or Comm attribute changes, we set the Sal and Comm attributes as Dependencies. Also, we set the AutoSubmit property (under UI Hints tab) for the Sal and Comm attributes.

SalCommAutoSubmit.jpg


Now, we are done with the model layer. We can now, create a jspx page and then Drag and Drop EmpView as ADF Table. After this, we create an Excel Workbook (macro enabled), enable ADF Desktop Integration for it, set the required Workbook Properties, and then add a Table based on the EmpView.

EmpTable.jpg



As there are no straight forward way in ADFdi to trigger a request to server when a value of a cell is changed, we will now add a DoubleClickActionSet for the Sal and Comm columns. This DoubleClickActionSet will have the Table.RowUpSync and Table.RowDownSync actions.

RowUpSyncDownSync.jpg


Above example image shows the DoubleClickActionSet for Sal column. In the same manner, we need to add the DoubleClickActionSet for the Comm column as well.

Now, we have the workbook, that would fetch the SalPlusComm attribute (after recalculation in the model), when we change the Sal / Comm attribute and then double click on that column. To do this automatically when the user tabs out / presses enter key on the cells, we'll write a bit of VBA Code on the Worksheet where we've this table (Go to Developer Tab and Click on Visual Basic).

Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Column = 14 Or Target.Column = 15 Then
    Target.Select
    Application.CommandBars("Cell").Controls("Invoke Action...").Execute
  End If
End Sub
Excel would trigger Worksheet_Change event when a cell in the worksheet is modified. So, we would code our logic in that event. The above code assumes that Sal column is present in the N (14th) column on the worksheet and Comm column is present in O (15th) column. So, we would execute our logic only when the contents in these two columns change.

ADFdi would provide a context menu (Invoke Action...) when a DoubleClickActionSet is added to a particular column. We'll make use of that context menu and invoke it programatically.


InvokeAction.jpg



We invoke that context menu programatically using the following line of code

Application.CommandBars("Cell").Controls("Invoke Action...").Execute

Now, we run our workbook, modify the value of Sal column for any row and tab out of that field would automatically update the value of SalPlusComm column.


EmpTable1.jpg
EmpTable1.jpg


Here, a simple example (Transient Attribute) is taken for the explanation. In the similar fashion, we can also have a DoubleClickActionSet to contain a method in the Impl that would perform this calculation as well.

Tip: If you are not able to view the image fully, right click on the image and choose View Image option to see it completely.


Wednesday Feb 01, 2012

Custom Upload options in ADF Desktop Integration

About

     In ADFdi enabled excel workbook while uploading the changes performed in ADF Table,standard upload options dialog appears like below.

uploadoptions_dialog.PNG

    In this article,we will see how to customize these options in a dialog.

Usecase

     Let us take a simple example of Employee table.

Implementation

Assumption: An ADF Web Application with ADF Desktop Integration enabled workbook having Employee table as below screenshot is available.

adfdi1_table.PNG


Now let's create a new jspx page titled 'UploadOptions.jspx'.
The below code adds two checkboxes and buttons.Let's copy this into the Source view of jspx page.

<!-- Check box for AbortUploadOnFailure -->
<af:selectBooleanCheckbox text="Abort Upload On Failure" id="sbc1"
  value="#{requestScope.abortUploadOnFailure}" autoSubmit="true" selected="true"/>

<!--Check box for DownloadAfterUpload -->
<af:selectBooleanCheckbox text="Download After Upload" id="sbc2" autoSubmit="true"
  value="#{requestScope.downloadAfterUpload}"/>

<!--Command button for Continue action -->
<af:button text="Continue" id="b1" inlineStyle="width:100px;" partialSubmit="false">
<af:setActionListener from="continue" to="#{requestScope.action}"/>
</af:button>

<!-- Command button for Abort action -->
<af:button text="Abort" id="b2" inlineStyle="width:100px;" partialSubmit="false">
<af:setActionListener from="abort" to="#{requestScope.action}" />
</af:button>


The UploadOptions.jspx page now looks like below:

custom_upload_jspx.PNG

Below Span elements have to be used to perform custom upload actions in ADFdi Table.

ADFdiCloseWindow - When a web page has to be closed,this span element can be set to
Continue  - to close the web page and invoke next action in actions set or
Abort       - to close the web page and terminate the action set.
ADFdiAbortUploadOnFailure - If this element is set to True, the action set stops uploading if it encounters a failure. If the element references False, the action set attempts to upload all rows and indicates if each row succeeded or failed to upload.
ADFdiDownloadAfterUpload - If this element is set to True, the action set downloads data into the ADFdi Table component after the action set uploads modified data.

Let us add the below code at the end of tag Form in source view of jspx,to include the above mentioned span elements.

<!-- Closes the Upload Options dialog and then invokes next action in the action set-->
<f:verbatim rendered="#{requestScope.action eq 'continue'}">
<span id="ADFdiCloseWindow">Continue</span>
</f:verbatim>


<!-- Closes the
Upload Options dialog but aborts next actions in action set-->
<f:verbatim rendered="#{requestScope eq 'abort'}">
<span id="ADFdi
CloseWindow">Abort</span>
</f:verbatim>


<!-- If the span element is set to
  True, the action set stops uploading if it encounters a failure.
  False, the action set attempts to upload all rows and indicates if each row succeeded or failed to upload. -->
<f:verbatim>
<span id="ADFdiAbortUploadOnFailure">${requestScope.abortUploadOnFailure}</span> 
</f:verbatim> 


<!--If the span element is set to
True, the action set downloads data from the Fusion web application to the ADF Table after the action set uploads modified data -->
<f:verbatim>
<span id="ADFdi
DownloadAfterUpload">${requestScope.downloadAfterUpload}</span>
</f:verbatim>


In ADFdi excel workbook,let us add this new jspx file as dialog before Table.Upload action in Ribbon Commands of Worksheet Properties.

worksheet_properties.PNG

Now we run the excel workbook and download data into ADF Table as shown above.Let's update a row by changing the Sal=4000 of Martin.

update2_ADFdiTable.PNG

On clicking Upload Ribbon command like below:

Uplaod_ribbon.PNG

the custom upload actions dialog gets opened with 'Abort Upload On Failure' check box selected by default.

custom1_upload_workbook.PNG
We can select 'Download After Upload' check box and click on Continue button.We can see data updated and downloaded again with new value like below:

updated2_table.PNG

This is a simple example of how upload options can be customized. Using this, we can add more custom options to the dialog, which is not available in the standard upload options dialog. We will see such options sooner in my next blog.

About

Tips and Tricks from Oracle's JDeveloper & ADF QA

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today