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
Thank You Eng/Karim it really a great topics in ADF.
ReplyDelete