Follow by Email

Monday, 23 January 2017

Using external XML file as list resource bundle in ADF Application


Hello All

In this post I am talking about using external XML file as list resource bundle in ADF Application

Using this approach we need not to hard code component's label and messages , all labels and messages will be read from XML file and no need to open application to change any resource , In short we can update resources without compiling and redeploying application

A resource bundle contains a number of named resources, where the data type of the named resources is String. Resource bundles can be either Java classes, property files, or XLIFF (XML Localization Interchange File Format ) files.

Let's implement this, Created model using Departments table of HR Schema


Right click on viewController project and go to properties , Select Resource Bundle, Change default project bundle name to listresourcebundle.view.bundle.Resource and check Automatically Synchronize Bundle checkbox



Now click on Ok button of Project Properties dialog and click yes on the popup dialog to change bundle name


After changing default resource bundle name , Open faces-config.xml file (Under WEB-INF Folder)

Go to Application tab and add a line in Resource Bundle Section, In Base Name put the whole bundle name and in Var Name use any string that will be further used to fetch resource values 


Create a page in viewController project and drop Departments viewObject as af:table on page and to create Resource Bundle Java class select any column of af:table and Select Text Resource in Header Text property


You can see a Resource.java class in created in viewController project


Now create List Resource XML file in this format


<?xml version="1.0" encoding="windows-1252" ?>
<bundle>
<label>
 <key>RES.1</key>
 <value>Department Id</value>
</label>
<label>
 <key>RES.2</key>
 <value>Department Name</value>
</label>
<label>
 <key>RES.3</key>
 <value>Manager Id</value>
</label>
<label>
 <key>RES.4</key>
 <value>Location Id</value>
</label>
</bundle>

Saved this file as Resource_En.xml in D drive of my system, Now see the code of Resource.java file to process and read resource values from this XML file
The java.util.ListResourceBundle class manages resources in a name and value array. Each java.util.ListResourceBundle class is contained within a Java class file


package listresourcebundle.view.bundle;

import java.io.File;

import java.util.ListResourceBundle;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Resource extends ListResourceBundle {
    
    //Path to XML Resource File
    private String Res_path = "D://Resource_En.xml";
    
    //Initialize an Object Array to hold label and key values
    public Resource() {
        for (int i = 0; i < 5000; i++) {
            contents[i][0] = "";
            contents[i][1] = "";
        }
    }

    private static final Object[][] contents = new Object[5000][2];

    /**Method to process XML file and get key and value of resource and put that in array
     * @return
     */
    public Object[][] getContents() {
        try {

            File file = new File(Res_path);
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc = db.parse(file);
            doc.getDocumentElement().normalize();
            NodeList nList = doc.getElementsByTagName("label");

            for (int temp = 0; temp < nList.getLength(); temp++) {
                Node nNode = nList.item(temp);
                if (nNode.getNodeType() == Node.ELEMENT_NODE) {

                    Element eElement = (Element) nNode;
                    contents[temp][0] = getTagValue("key", eElement);
                    contents[temp][1] = getTagValue("value", eElement);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return contents;
    }

    private static String getTagValue(String sTag, Element eElement) {
        NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes();
        Node nValue = nlList.item(0);
        return nValue.getNodeValue();
    }
}

Now configuration part is done and to apply resources in page , Select column and go to header text property and from expression builder select var name from Faces' Resource Bundles and put respective key in single quote like this


Repeat this step for all columns


Now run and check application, All labels are fetched from XML file


Sample ADF Application (Jdeveloper 12.1.3)- Download
Cheers :) Happy Learning

Friday, 20 January 2017

Import data from XLS and XLSX (Excel) to ADF Table Using Apache POI

ADF provides feature to export data to excel using export collection listener with just one click but there is no built in feature to upload data from excel file to ADF table

For this requirement we have to use some other API and Apache POI is best for excel communication, In this post I am going to discuss about uploading excel (XLS and XLSX) file data to ADF table

Tuesday, 17 January 2017

ADF Basics: Duplicate Record Validation Using Custom Java Method


Hello All

Recently I have posted about duplicate record validation using model level business rules (Unique Key Validation) but sometimes we need to check some more conditions or we have some other logic that should be checked before validating the input then in that case we can write custom java method in model (Application Module Impl class) and call it in bean validator using binding layer

Monday, 16 January 2017

Uploading mulitiple files to server path in Oracle ADF using af:inputFile



Hello All :)

Previously I have posted about uploading and downloading files from server path (Refer this post for more clarification), In that post I have described the process of uploading single file at a time but sometimes we need to upload multiple files at a time and for that requirement we can use same code with little modification


So In this post we'll see that how can we upload multiple files at a time using af:inputFile, Here I am using same sample application that is used in previous post

Thursday, 12 January 2017

ADF Basics: Duplicate Record Validation Using Model Level Business Rules


Hello All

Hope you all are doing well :)

When we are creating any data entry form , at that time preventing duplicate entries for some of attributes is very basic validation requirement .

Suppose We are creating a form to make new Departments entry and  there should not be two departments with same name so for this type of validation we need not to write single line of code in Oracle ADF as there are predefined business rules for basic validation

Thursday, 5 January 2017

Get Installed Printer List using Java, Print a file with default Printer




This post shows that how can we get installed printers list using PrintServiceLookup class


Implementations of this class provide lookup services for print services


Wednesday, 4 January 2017

Invitation to Write for My Blog - A New Start on this New Year


Hello All

I am thinking about doing something new in this New Year and for that I thought about guest blog posts for deeper knowledge and information

If you have some great content that you would like to share with world then I have this good news for you, I am accepting guests blog posts for this blog (www.awasthiashish.com)

Monday, 2 January 2017

Best Wishes- Happy New Year 2017

Another year filled with memories and joyous times has passed

Another year filled with endless possibilities and happiness has come


You all have made my year very special, and I wish a very Happy New Year to all of you


Every New Year gives you the perfect chance to start something new and fresh. So do your bit this year and make the world a better place for yourself and others


Thanks everyone for your love and support :) :)