Saturday, July 27, 2013

Javascript solution for preventing non-numeric characters in ADF Faces

You can use JavaScript to filter out non-numeric characters from a ADF Faces Input Text field by following the below approach. I tried many methods found in various sites but to filter out the special characters like !@#$%^&*() nothing worked for me.

First of add the following JavaScript resource as below.

            <af:resource type="javascript">

              var shiftDown = false;

              processKeyUp = function (e) {

                  var key = e.getKeyCode();

                  if (key == 16) {

                      shiftDown = false;

                  }

              }

              processKeyDown = function (e) {

                  var key = e.getKeyCode();

                  if (key == 16) {

                      shiftDown = true;

                  }

 

                 // Allow: backspace, delete, tab, escape, enter and .

                  if (key == 46 || key == 8 || key == 9 || key == 27 || key == 13 || key == 110 || key == 190 ||

                  // Allow: home, end, left, right

                  (key >= 35 &amp;&amp; key &lt; 40))

                  {

                      // let it happen, don't do anything

                      return;

                  }

                  else {

                      // If non numeric or shift is pressed then stop the keypress

                      if (shiftDown || (key &lt; 48 || key > 57) &amp;&amp; (key &lt; 96 || key > 105)) {

                          e.cancel();

                      }

                  }

              };

            </af:resource>

 

In JSF page Fragments remember to add this inside a layout container like PanelformLayout.

I faced problems with rendering the page when the JavaScript had < and && in the conditions so I substituted with &lt; and &amp;&amp;

Now add two Client Listeners for the Input Text field as shown below

            <af:inputText value="#{bindings.Salary.inputValue}" label="#{bindings.Salary.hints.label}"

                          required="#{bindings.Salary.hints.mandatory}"

                          columns="#{bindings.Salary.hints.displayWidth}"

                          maximumLength="#{bindings.Salary.hints.precision}"

                          shortDesc="#{bindings.Salary.hints.tooltip}" id="it7" styleClass="numeric">

                <f:validator binding="#{bindings.Salary.validator}"/>

                <af:clientListener method="processKeyDown" type="keyDown"/>

                <af:clientListener method="processKeyUp" type="keyUp"/>

            </af:inputText>

 

That’s it.

Saturday, July 13, 2013

JDeveloper/ADF 12c : New Features

Two new behaviors in ADF 12c
Been trying for a solution for this issue and 12c has added two behaviors that do just that:

From the Tag Doc:

The checkRegionUncommittedDataBehavior tag is a declarative way to show a warning about uncommitted data within a certain region component


The checkRegionUncommittedDataBehavior tag is a declarative way to show uncommitted data warning for command components with immediate="true"

Tuesday, August 25, 2009

Integrating BI Publisher into Jdeveloper & ADF

BI Publisher API can be integrated with your ADF faces application to generate professional quality reports. This document assumes that you have access to Oracle BI Publisher and
have the necessary license to use it.

Advantage of BI Publisher is that you can create the Report Layout Template using Microsoft Word.

Creating an RTF template document for BI Publisher is out of scope of this document.

The basic needs for generating report with BI Publisher

  1. Data in XML Format
  2. RTF Template

BI Publisher API can be used to convert the RTF template into an XSL file which will finally be used by the BI Publisher API for generating the final output

The example uses the sample schema SCOTT and tables DEPT and EMP

Create a new Fusion Web Application (ADF)

Run the 'Business Components from Tables' wizard, select tables DEPT and EMP and generate the view objects for both. In my sample application I generated only read only
view objects.

Edit DeptView and the navigate to Java Options and select the check box for Generate ViewObject Class

Open DeptViewImpl.java and add the following method.







public void saveAsXMLFile(String fileName) {

Node n = writeXML(-1,XMLInterface.XML_OPT_ALL_ROWS);

java.io.File file = new java.io.File(fileName);

PrintWriter output = null;

try {

output = new java.io.PrintWriter(file);

((XMLNode)n).print(output);

} catch (IOException e) {

System.out.println(e.getMessage());

} catch (Exception e) {

System.out.println(e.getMessage());

} finally {

if (output != null) {

try {

output.close();

} catch (Exception e) {

System.out.println(e.getMessage());

}

}

}

}


I have taken the idea for above from the site http://kohlivikram.blogspot.com/2009_04_01_archive.html

Many thanks for the sample scripts provided there.

The above method will generate the XML as shown below







<DeptView>

<DeptViewRow>

<Deptno>10</Deptno>

<Dname>ACCOUNTING</Dname>

<Loc>NEW YORK</Loc>

<EmpView>

<EmpViewRow>

<Empno>7782</Empno>

<Ename>CLARK</Ename>

<Job>MANAGER</Job>

<Mgr>7839</Mgr>

<Hiredate>1981-06-09</Hiredate>

<Sal>2450</Sal>

<Deptno>10</Deptno>

</EmpViewRow>

<EmpViewRow>

<Empno>7934</Empno>

<Ename>MILLER</Ename>

<Job>CLERK</Job>

<Mgr>7782</Mgr>

<Hiredate>1982-01-23</Hiredate>

<Sal>1300</Sal>

<Deptno>10</Deptno>

</EmpViewRow>

</EmpView>

</DeptViewRow>

</DeptView>


This finishes our first requirement of generating XML data

Open the Project Properties for the ViewController project and add the below libraries

Collections.jar

I18nAPI_v3.jar

Versioninfo.jar

Xdocore.jar

Xmlparserv2-904.jar

Create a new jspx page and insert a Panel Group Layout component into the page.

Insert a Button component inside the Panel Group Layout

Insert a File Download Action Listener component inside the Button and set the
below properties

Content Type: application/pdf
File Name: deptemp.pdf

Click the Edit menu for the Method property and create a new managed bean named
ADFBI

Add a new method for the above bean named generateReport and click OK

Jdeveloper will generate a new java file named ADFBI.java, open this file for editing
and modify it as shown below








package com.rkc.view;

import com.rkc.model.DeptViewImpl;

import java.io.IOException;

import java.io.OutputStream;

import javax.faces.context.FacesContext;

import oracle.adf.model.BindingContext;

import oracle.apps.xdo.XDOException;

import oracle.apps.xdo.template.FOProcessor;

import oracle.apps.xdo.template.RTFProcessor;

import oracle.binding.BindingContainer;

public class ADFBI {

public ADFBI() {

}

public void generateReport(FacesContext facesContext,

OutputStream outputStream) {

DeptViewImpl dept =
(DeptViewImpl)BindingContext.getCurrent().getDefaultDataControl().getApplicationModule().findViewObject("DeptView1");

dept.saveAsXMLFile("c:/temp/deptemp.xml");

try {

RTFProcessor rtfProcessor = new RTFProcessor("c:/temp/deptemptmpl.rtf");

rtfProcessor.setOutput("c:/temp/deptemp.xsl");

rtfProcessor.process();

FOProcessor processor = new FOProcessor();

processor.setData("c:/temp/deptemp.xml");

processor.setTemplate("c:/temp/deptemp.xsl");

processor.setOutput(outputStream);

processor.setOutputFormat(FOProcessor.FORMAT_PDF);

processor.generate();

} catch (IOException e) {

System.out.println("IOException " + e.getMessage());

} catch (XDOException e) {

System.out.println("XDOException" + e.getMessage());

}

}

}



In order to the above code to you need to do the below steps

Right click the jspx page and then select Go to Page Definition menu. If the Page Definition dose not exist it will be created and opened. Now you have to add an iterator under the executables section. I created DeptView1Iterator. This will ensure that the methods in BindingContext will not throw any NullPointerException

Also the deptemptmpl.rtf file must exist in the folder named C:\temp

Now run the application and click the Generate Report button to get your output
in a PDF file.

Sample application can be downloaded from here






Sunday, March 11, 2007

Integrating Jasper Reports with JDeveloper

I have created a sample application which demonstrates how Jasper reports can be integrated with Jdeveloper.

Example application can be downloaded from
http://web.omnidrive.com/APIServer/public/iPBWqziXIQFPB8vi5Wz5YptO/JasperReport.zip

You can also download the report I used from
http://web.omnidrive.com/APIServer/public/Zr0Eekn3xbOL2BYmSxTX0nOY/Reports.zip

adf-faces-impl.jar and adf-faces-api.jar has been removed from the zip file for making the zip file size smaller. You can copy the same files from your \jlib folder to the ViewController\public_html\WEB-INF\lib folder.

The reports.zip can be unzipped to a folder named D:MyWork\Reports. If you are putting the reports file in some other folder then make the necessary changes in the web.xml file to change the value for the initialization parameter 'ReportsFolder'

I am also assuming that you have installed iReports into the folder C:\Program Files\JasperSoft\iReport-1.2.7

For the example i used JDevloper 10.1.3.1 and iReports 1.2.7 (which is an IDE for developing reports for JasperReports)

The application is based on the scott schema so create a connection named scott for the model project.

Friday, March 2, 2007

Configuring Apache 2.2 + Tomcat 5.5.20 with mod_jk for load balancing

For one project we are using Apache Tomcat for deploying our application developed in Jdeveloper using the ADF BC - JSF technology. We were required to configure load balancing between two tomcat instances. Here is how we did it.

http://docs.google.com/Doc?id=dpkjppk_2g47gm5

Friday, February 9, 2007

A Generic Simple Search for ADF Faces

In this tutorial we will be building a simple search functionally which can be added to any ADF Faces Table. The figure below gives a preview of what we are going to build.



The Select Items in the drop down is dynamically generated from the meta-data information of the view.

Here's how to build this.

Create a new Web Application using the JSF, ADF BC Template.

Working with the Model project

Creating a Framework Extension Class for ViewObjectImpl with the Simple search functionality.

Create a Java class named CustomViewObjectImpl and modify the code to look like the following


package com.regee.adfext;

import oracle.jbo.ViewCriteria;

import oracle.jbo.ViewCriteriaRow;

import oracle.jbo.server.ViewObjectImpl;


public class CustomViewObjectImpl extends ViewObjectImpl {

public CustomViewObjectImpl() {

}

public void searchView(String searchAttributeName, String searchText){

if (searchAttributeName==null) return;

ViewCriteria vc =this.createViewCriteria();

ViewCriteriaRow vcRow = vc.createViewCriteriaRow();

vcRow.setAttribute(searchAttributeName,searchText );

vc.addElement(vcRow);

this.applyViewCriteria(vc);

this.executeQuery();

}

}


Setting up Project-Level Preferences for Framework Extension Classes

Open the Project Properties window for the 'Model' project and go to the section 'Business Components BaseClasses' and change the View Object base class to com.regee.adfext.CustomViewObjectImpl


Creating the Business Components (Employee, EmployeeView, AppModule)

Use the 'Business Components from Tables' wizard to generate the necessary entity, view and application module.

Exposing the 'searchView' method in the Client Interface.

Edit the EmployeeView and in the 'Client Interface' section, move the searchView method from the Available list to Selected list.


Working with the ViewController Project


Creating a resource file to place the Label Texts

From the ViewController project create a resource file named Resources.properties using the 'Simple Files' wizard and add the following content in it.


EmployeeId= Employee ID

FirstName= First Name

LastName= Last Name

Email= Mail

PhoneNumber= Phone #

HireDate = Date of Hire

JobId= Job

Salary = Salary

CommissionPct= Commission %

ManagerId= Manager

DepartmentId= Department


Create the EmployeeSearch.jspx page using the JSF JSP page wizard. Remember to select the 'Automatically Expose UI Components in a New ManagedBean' in the wizard so that JDEveloper will generate a backing bean for this page.


Add the <f:loadBundle> tag to the page just before the <f:view>tag to enable the resource bundle usage for this page.


Add ADF Faces Table based on the EmployeeView1.


Add a PanelHorizontal for placing our search components above the table.


Add a SelectOneChoice component inside the PanelHorizontal, which will display the attribute list.

Delete the SelectItems tag which is appearing inside the SelectOneChoice tag (remember to delete this from the structure window)

From the Properties window change the ID to selectOneChoiceSearchAttribute

Go to source of this SelectOneChoice component and replace the code with the following


<af:selectOneChoice

label="SearchOn" value="EmployeeId"

binding="#{backing_EmployeeSearch.selectOneChoiceSearchAttribute}"

id="selectOneChoiceSearchAttribute">

<af:forEach items="#{bindings.EmployeesView1Iterator.attributeDefs}"

var="item">

<af:selectItem label="#{res[item.name]}"

value="#{item.name}"

rendered="#{item.queriable}"/>

</af:forEach>

</af:selectOneChoice>

The value property of the selectInputChoice component is set to the value EmployeeId so that this comes as default in the dropdown list box.

Add the inputText component in which the user can enter the search text.

Change the ID of this to inputTextSearchText

From the Data Control Palette expand the EmployeeView1 node and drag the searchView method onto the PanelHorizotal as an ADF Command Button and in the ensuing Áction Binding Editor window set the following values

searchAttributeName= ${backing_EmployeeSearch.selectOneChoiceSearchAttribute.value

searchText = ${backing_EmployeeSearch.inputTextSearchText.value}

To change the order of columns in the dropdown change the order in the Page Definition.

Now run the application.

You can download a sample application based on the HR schema from the following link.

http://web.omnidrive.com/APIServer/public/bo40n456pBMyGmYZBMcohX2A/SimpleSearch.zip

I have removed the adf-faces-impl.jar and adf-faces-api.jar from the zip for making the zip size smaller. You can copy the corresponding files from the \jlib folder into the ViewController\public)html\WEB-INF\lib folder.

Thursday, January 18, 2007

JDeveloper Layout dissappearing

When this happens first open the project properties page and ensure that for all JSP tag libraries 'Execute Tags in JSP Visual editor" is checked.

And open the jspx page again and check whether the layout is coming properly.

If not try the following steps

  1. Close JDeveloper
  2. Take a backup of you Web Application project.
  3. Remove the folders "classes" and "model"
  4. Now run Jdeveloper and voila your layout is back

I think this is because JDeveloper uses the classes to display the format in the design mode