Thursday, June 2, 2011

Generate dynamic report in ADF App

DynamicJasperReport fusion web sample application implemented using JDeveloper 11.1.1.5.0 and built on HR schema included Jasper and DynamicJasper lib can be downloaded from HERE.

This example show you how to use DynamicJasper in ADF application, it help you to design, build and export as pdf your jasper report at run time.

You may use it in application which you let end user to add some properties for element in run time to generate it’s report without redeployment, where you can display different metadata and data each time you run it

DynamicJasper (DJ) is an open source free library that hides the complexity of Jasper Reports, it helps developers to save time when designing simple/medium complexity reports generating the layout of the report elements automatically.

DJ creates reports dynamically, defining at runtime the columns, column width (auto width), groups, variables, fonts, charts, crosstabs, sub reports (that can also be dynamic), page size and everything else that you can define at design time

For more information about DynamicJasper

Regards

Karim Hasan

Sunday, June 27, 2010

Defining LOV on Transient attribute and hide foregin key by PL/SQL helper method (ADF Jdev11g)

As mention in Andrejus Baranovskis's blog Defining LOV on reference attribute ,its quite common requirement to have reference attribute shown in LOV, and not its code. I used another way to achieve this by Transient attribute and Pl/Sql helper method and hope it is useful,
Download sample application from Here , sample use Jdev11g ps3 and HR schema
and create PL/Sql Method to get department name as follow
FUNCTION get_DepartmentName(dept NUMBER) RETURN varchar2 as
cursor crs is
select department_name from departments where department_id=dept;
begin
for i in crs loop
return i.department_name;
end loop;
return null;
end;

1. adding transient attribute and make it always updatable and mark "Mapped to Column or SQL" and "Selected in Query" check box ,then write your Pl/SQL method call in the expression section below to be selected in your view object query, to ensure that it will be retrive the department name in browsing mode


2. create LOV on your transient attribute which retrive department_name and department_Id



Monday, February 8, 2010

Handle Soft Delete using Custom Properties (Jdev11g ADF)

I read Generic Handle softdelete At husain dalal's blog and I would like to show another way to handle soft delete using custom property for DeletedFlag attribute using custom properties,
You will notice that DeletedFlag attribute type is Date where it will be entered as new Date("0001-01-01") in Insert operation and will set as system date in delete operation where it will be more better to know the date of delete operation


Now,
1. Create a new Fusion ADF Application and add a new java class that extends oracle.jbo.server.EntityImpl
2. In the CustomEntityImpl override the following methods:
a. remove() - To set the value of column with custom property(DeletedFlag,”YES”) to deleted value.
b. doDML() - During delete, to force an entity object to be updated instead of deleted. And during insert to default the value of column with custom property(DeletedFlag,”YES”) to new Date("0001-01-01").
public int getSoftDeletedColumn() {
int colIndex = -1;
for (AttributeDef def : getEntityDef().getAttributeDefs()) {
if (((AttributeDefImpl)def).getProperty("DeletedFlag") == "YES") {

colIndex = def.getIndex();
}

}
return colIndex;

}

@Override
public void remove() {
int deleteCol = getSoftDeletedColumn();
if (deleteCol != -1) {
setAttribute(deleteCol,
new Date(new Timestamp(System.currentTimeMillis())));
}

super.remove();
}

@Override
protected void doDML(int operation, TransactionEvent transactionEvent) {
int deleteCol = getSoftDeletedColumn();
if (EntityImpl.DML_DELETE == operation && deleteCol != -1) {
operation = DML_UPDATE;
}
if (EntityImpl.DML_INSERT == operation && deleteCol != -1) {

setAttribute(deleteCol, new Date("0001-01-01"));
}
super.doDML(operation, transactionEvent);

}
3. In the Application Navigator, double-click the entity you want to edit.
4. In the overview editor, click the Attributes navigation tab, and double-click the attribute you want to edit.
5. In the Edit Attribute dialog, then click the Custom Properties node add new property of
Name=DeletedFlag, value =YES then add



Download workspace from here but don't forget to generate example table

Thursday, February 4, 2010

Quick translation using GoogleTalk

if you want get quick translation from Arabic to English add this friend to your GoogleTalk friend list
ar2en@bot.talk.google.com
and
if you want get quick translation from English to Arabic add this friend to your GoogleTalk friend list
en2ar@bot.talk.google.com

then chat with
you can change locale letters for different language

Wednesday, January 27, 2010

Assigning the Primary Key Value Using an Oracle Sequence and Custom Properties for multiple entitys

This is practice of using custom properties where you can assign the value to a primary key when creating a new row using an Oracle sequence. by single Java file that can be reused by multiple entity objects.
CustomEntityImpl framework extension class on which the entity objects are based. Its overridden create() method tests for the presence of a custom attribute-level metadata property named SequenceName and if detected, populates the attribute's default value from the next number in that sequence.

To assign the primary key value using an Oracle sequence:
1. Create the CustomEntityImpl.java file in your project, and insert the code
package eg.alex.karim.model.frameworkExten;
import oracle.jbo.AttributeDef;
import oracle.jbo.AttributeList;
import oracle.jbo.server.EntityImpl;
import oracle.jbo.server.SequenceImpl;

public class CustomEntityImpl extends EntityImpl {
protected void create(AttributeList attributeList) {
super.create(attributeList);
for (AttributeDef def : getEntityDef().getAttributeDefs()) {
String sequenceName = (String)def.getProperty("SequenceName");
if (sequenceName != null) {
SequenceImpl s = new SequenceImpl(sequenceName,getDBTransaction());
setAttribute(def.getIndex(),s.getSequenceNumber());
}
}
}
}
2. In the Application Navigator, double-click the entity you want to edit.
3. In the overview editor, click the Attributes navigation tab, and double-click the attribute you want to edit.
4. In the Edit Attribute dialog, set the attribute Type from DBSequance to Number, and then click the Custom Properties node.

5.enable the generation of custom Java classes for an entity object and let it extend CustomEntityImpl.java.

you can download workspace from Here
Summary
by using custom properties you may categorize some attriutes which shared in it's behavior









Saturday, January 2, 2010

Wednesday, October 28, 2009

Validated arabic Letters Data Types Using Domains (using JDeveloper 11g ADF Domain)

Validated (Arabic Letters) Data Types Using Domains

However, these approaches can become tedious quickly in a large middle-east application. Fortunately, ADF Business Components offers an alternative that allows you to create your own Arabic letters data type that represents an names in arabic in some forms. After centralizing all of the sanity-checking regarding Arabic letters into this new custom data type, you can use the ArabicLettersDomain as the type of every attribute in your application that validate Arabic letters only and common separators. By doing this, you make the intention of the attribute values more clear to other developers and simplify application maintenance by putting the validation in a single place.
ArabicLettersDomain are Java classes that extend the basic data types like String to define Arabic letters data types in a way that are inherited by any entity objects or view objects that use the domain as the Java type of any of their attributes.
shows the validate() method for a simple ArabicLettersDomain
domain class. It tests to make sure that the mData value contains an Arabic letters only,
and if it any other letter in any language, then the method throws DataCreationException referencing
an appropriate message bundle and message key for the translatable error message.




Simple ArabicLettersDomain String-Based Domain Type with Custom Validation
protected void validate() {
// ### Implement custom domain validation logic here. ###
int count = 0; for (int i = 0; i < mData.length(); i++) {
for (int j = 0; j < arabicChars.length; j++) {
if (mData.charAt(i) == arabicChars[j]) {

count++;
break;
}
}
}

if (count != mData.length()){\
throw new DataCreationException(ErrorMessages.class, ErrorMessages.ARABIC_ONLY, null, null);
}
}

Validate Method Should Throw DataCreationException If Sanity Checks Fail
Typically, the only coding task you need to do for a domain is to write custom code
inside the generated validate() method. Your implementation of the validate()
method should perform your sanity checks on the candidate value being constructed,
and throw a DataCreationException in the oracle.jbo package if the validation
fails.
In order to throw an exception message that is translatable, you create a message
bundle class in the same common package as your domain classes themselves. The message bundle returns an array of
{MessageKeyString,TranslatableMessageString} pairs.
Custom Message Bundle Class For Domain Exception Messages
package it.adf.karim.domain.common;
import java.util.ListResourceBundle;

class ErrorMessages extends ListResourceBundle {

public static final String ARABIC_ONLY = "30004";

private static final Object[][] sMessageStrings =
new String[][] { { ARABIC_ONLY,
"Sorry, you may enter arabic letters only" }/*,{},{} you may add a new pairs for another message*/ };

/**
* Return String Identifiers and corresponding Messages
* in a two-dimensional array.
*/
protected Object[][] getContents() {
return sMessageStrings;
}
}


try it Here

for more information about Oracle ADF domain:

Oracle® Fusion MiddlewareFusion Developer's Guide for Oracle Application Development Framework 11g Release 1 (11.1.1)

37.1 Creating Custom, Validated Data Types Using Domains

Thank you