Wednesday, April 20, 2011

Flex 4.1: Creating a new locale for i18N capable application

What to do, if you are planning to create a flex application that will be internationalized application with locals, and your Flex SDK doesn’t support that locals? Let’s solve it as the following.

Note: there is a tool bundled with Flex SDK (copylocale.exe) that provides creation the new locals.
This example applied to flex SDK 4.x and above.
Usage: copylocale src_locale(language_country) dst_locale(language_country)

Let’s take an example of Arabic support, the default Flex SDK doesn’t support Arabic as local so we need to add it.
Process:
If you have flex SDK or you have installed the adobe flash builder 4.x Standard or premium go to the following path.
  1. You have to download Java JRE to allow the tool to run. ***Very important…..
  2. For flex SDK, if downloaded and unzipped the SDK under folder named C:\ Adobe Flex SDK 4.1
    1. Go to C:\ Adobe Flex SDK 4.1\bin
  3. For installed adobe flash builder 4.x
    1. Go to C:\Program Files (x86)\Adobe\Adobe Flash Builder 4\sdks\4.1.0\bin         windows x64 bit
    2. Go to C:\Program Files\Adobe\Adobe Flash Builder 4\sdks\4.1.0\bin                   windows x32 bit
  4. Open CMD command prompt and point to the above path
    1. C:\Program Files (x86)\Adobe\Adobe Flash Builder 4\sdks\4.1.0\bin>
    2. Type the copylocale command to copy the local you want as the following
      1. I want to create Arabic Egyptian local.
      2. C:\Program Files (x86)\Adobe\Adobe Flash Builder 4\sdks\4.1.0\bin> copylocale en_US ar_EG
      3. You will see verbose lines for the tool until it finished and returns to the command line prompt.
  5. To check that your local is created, go to the following path “C:\Program Files (x86)\Adobe\Adobe Flash Builder 4\sdks\4.1.0\frameworks\locale” and you should see you created locale ar_EG.
  6. Congratulation you have done.
Some troubleshooting:
P1 - If you run the copylocale and get the following error:
>
Error loading: C:\Program Files\Java\jdk1.6.0_21\jre\bin\server\jvm.dll
Answer: this happened when you haven’t installed the java JRE, or installed the JRE x64 bit version.
Solution:
1- Install the x32 bit version of java JRE.
2- Point to already 32bit java JRE installed. Or to JRE bundled with already installed application, if you want to keep existing x64 bit version.
do the following
  1. Go to the “C:\Program Files (x86)\Adobe\Adobe Flash Builder 4\sdks\4.1.0\bin” and locate the following file “jvm.config”.
  2. Edit the file and locate the line “java.home=”
  3. Make it “java.home=E:/Utilities/Oracle/Middleware/JDev11gU2/jdk160_05”.  For example
    1. Note forward “/” slash not backward “\” slash.
Run again and you will find everything goes successfully.

Database: SQLite connection from Java


Class.forName("org.sqlite.JDBC") ;
connection = DriverManager.getConnection("jdbc:sqlite:D:\\testdb.db ");

ADF: About JSF fragments, ADF regions, declarative components …

Starting application development with Oracle ADF and ADF Faces, some concepts may be hard to grasp at the beginning. Using Oracle ADF and ADF Faces, the following terminologies are used in the context of reuse of components and processes
JSF fragments
JSF page fragments are page definitions that run embedded in another JSF page. Fragments are like page includes in JavaServer Pages, with the difference that in Oracle ADF Faces they are usually used in the context of ADF regions or dynamic declarative components. You can also reference page fragments directly from a JSP includes tag added to a JavaServer Faces document (JSPX). However, in this case, and only if a page fragment has ADF bound content, you need to make sure the content of the page fragments ADF binding file (PageDef) is copied to the PageDef file of the parent page. Otherwise ADF queried data will not show.
ADF regions
ADF regions consist of an ADF Faces af:region tag, an ADF bounded task flow and page fragments. Page fragments that are used in a bounded task flow don't need to copy their ADF binding references to the parent container, which is a huge difference between JSP includes and ADF regions. ADF regions define an interactive area on a view, a JSF document or another JSF page fragment, that developers use to show a single view or a complete, multi-step, process. ADF regions can be statically or dynamically defined. In either way they require a PageDef file and a bounded task flow to reference. ADF regions help building desktop like web applications in which users stay for long on a single page while working on a business task.
Declarative components
Declarative components allow developers to build a composite component out of existing ADF Faces components. Declarative components exist in two flavors: library driven and dynamic declarative components (ddc). The tag library driven components are declaratively built from the File | New menu option. In the JSF view option you find a declarative component menu option that steps you through building your own ADF F aces component from existing ADF Faces components. You use tag library driven declarative components to build custom components with behavior, like a tool bar or a custom file-upload handler. The goal of building declarative components is to build re-usable components that simplify development and administration by avoiding duplicate page codes. Dynamic declarative components (DDC) are used within the scope of the web application they are defined in and cannot be re-used across applications. Their main usage is to build reusable layout artifacts or page area components. For example, a custom tab canvas is what you would build using DDC components.  
Page templates
Page templates are layout definitions that you use as a starter when building new pages to enforce consistent page layouts throughout applications and enterprises. Best practices are to build a page template using the ADF Faces Quick start templates. You cannot nest page templates, but you can use page templates on parent and child views (page fragments). A page template is the page level equivalent to a DDC component.
ADF Library
ADF libraries are special Oracle ADF archive files that you use to reuse bounded task flows (regions), page templates and declarative components. They are standard JAR files with extra information in the archive manifest file that allows you to import the library files into the Oracle JDeveloper Resource Palette for declarative reuse.
When designing an application you best start planning reuse of components and page segments. If you have an application wide look and feel that you can define as page template(s) then do this first. If you can identify areas within pages that you may need more often on other pages as well, without the pages to be identical from their layout, you use dynamic declarative components. For functionality like global toolbars or common and composite user interface logic, you build tag library based declarative components, which then can be used across applications too. An ADF region is an interactive and optionally also data centric page are that you use to show complete business processes in place. ADF regions are a friend for building rich Internet application interfaces and business centric web desktops. ADF libraries are the vehicle to deploy your reusable work.
Read more:
DDC
Reuse
Fragments, Templates, Declarative Components

Design pattern: DP in action - Inversion of Control


Applying the IoC pattern to a class means removing the creation of all object instances for which this class isn't directly responsible and passing any needed instances instead.
The instances may be passed using a specific constructor, using a setter, or as parameters of the methods needing them. It becomes the responsibility of the calling code to correctly set these domain objects on the called class.
Extreme Programming guru Ron Jeffries explains it:
My car has a diagnostic port and an oil dipstick. There is an inspection port on the side of my furnace and on the front of my oven. My pen cartridges are transparent so I can see if there is ink left.
And if I find it useful to add a method to a class to enable me to test it, I do so. It happens once in a while, for example in classes with easy interfaces and complex inner function (probably starting to want an Extract Class).
I just give the class what I understand of what it wants, and keep an eye on it to see what it wants next.

Security: Configuring projects for Java EE security annotations


Java EE security annotations are used in Enterprise Java Beans and JPA to protect user access to methods exposed in entities and the session façade. Creating a new EJB project in Oracle JDeveloper, or using the Java EE Web Application template to build a web application using EJB and ADF Faces, does not add the classes of the javax.annotation.security package to the project class path.
To solve this issue, and to make security annotations like @DenyAll available in the code editor, you need to add the WebLogic 10.3. Remote Client library as follows:
  1. Open the Model project properties by double clicking onto the project node or using the context menu
  2. Select Libraries and Classpath
  3. Click the Add Library button
  4. Search for and add the WebLogic 10.3. Remote Client entry.