Friday, 24 January 2014

How to load external resource bundle using java in ADF


Resource bundles are used to achieve Internalization in the Web based applications. They contain Key / Value pairs. Key identifies local-specific object in resource bundle.

Generally, when we create a “ViewController” project in ADF, It creates a default property file inside the project of “Resource Bundle Type” as Properties Bundle.

When an application is deployed, location of resource bundle will be inside EAR file as a result any update made in the component label requires application re-deployment. The issue can be resolved easily just placing resource bundle property file outside the EAR.

Below example will explain the scenario and configurations required:

Configure ListResourceBundle in project:

Goto-> project properties -> Resource Bundle
 
 

Register resource bundle in your application

Open faces-config.xml file and define resource bundle.

<resource-bundle>
      <base-name>view.MyResourceBundle</base-name>
      <var>viewcontrollerBundle</var>
    </resource-bundle>

Code snippet of java Class:

package view;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import java.util.Enumeration;
import java.util.ListResourceBundle;
import java.util.Properties;


public class MyResourceBundle extends ListResourceBundle {

    static final Object[][] contents = readPropertyFile();

    public Object[][] getContents() {
        return contents;
    }

    public static Object[][] readPropertyFile() {
        Object[][] data = null;
        try {
//Property file path in system
                       String nodeProFile =
                "C:\\Users\\Gopal\\Desktop\\resource bundle\\MyResourceBundle.properties";
            System.out.println("nodeProFile : " + nodeProFile);
            Properties prop = new Properties();
            //load a properties file
            prop.load(new FileInputStream(nodeProFile));
            Enumeration propKeys = prop.keys();
            System.out.println("Property size : " + prop.size());
            data = new Object[prop.size()][2];
            int i = 0;
            while (propKeys.hasMoreElements()) {
                String key = (String)propKeys.nextElement();
                String value = prop.getProperty(key);
                System.out.println("Key  " + key + " -> : " + value);
                data[i][0] = key;
                data[i][1] = value;
                i++;
            }
        } catch (FileNotFoundException fnfe) {
            fnfe.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
        return data;
    }
}

*Comments and feedback are most welcomed, Thanks.
 

Saturday, 28 September 2013

Add custom componet in ADF RTE

Attribute toolboxLayout in af:richTextEditor gives flexibility to add our own custom component in RTE. Using this attribute we can also remove default components of RTE.

Adding custom button :

<af:richTextEditor label="Custom button" toolboxLayout="all myBtn" id="rte1">
        <f:facet name="myBtn">
        <af:commandButton text="Submit" id="cb0"/>
        </f:facet> 
</af:richTextEditor>


Refrence : http://docs.oracle.com/cd/E21043_01/apirefs.1111/e12419/tagdoc/af_richTextEditor.html


*Comments and feedback are most welcomed, Thanks.

Thursday, 12 September 2013

How to Export adf table record in xls file using exportCollectionActionListener tag


Data of the collection components in ADF such as table, tree or treeTable can easily be exported in the form of xls file using ADF exportCollectionActionListener tag. It allows action events to export data from the colleection component.

<af:exportCollectionActionListener/> id attribute will refer to the collection component Id.

Find the sample code snippet for exporting department table records.

<af:panelCollection id="pc1" styleClass="AFStretchWidth">
            <f:facet name="toolbar">
              <af:toolbar id="t2">
                <af:commandToolbarButton text="Export" id="ctb1">
                  <af:exportCollectionActionListener type="excelHTML"
                                                     exportedId="table"
                                                     filename="DepartmentExcel"/>
                </af:commandToolbarButton>
              </af:toolbar>
            </f:facet>

            <af:table
id="table" ....
            ..................................  ...................
            ............ >
 </af:panelCollection>

By default the extension of the file downloaded will be xls. We can also export the record in doc format by just giving name of a file such as DepartmentExcel.doc in the attribute filename.




*Comments and feedback are most welcomed, Thanks.

Wednesday, 11 September 2013

How to select current row in adf table and perform delete operation

ADF table component is used to display the VO records in tabular form. It has its own many in-built features such as sorting, filtering and we can add other features like detach, manage columns, exporting data in excel file etc using af:panelCollection and toolbar facet component.

It also have row selection both single/multiple. Row selection is very important in respect of performing operations of particular rows.

In this blog I will show how we can get the current row of the table, fetching the primary key of the record and performing the delete operation using java code.

Let us assume our table is having a binding attribute mapped to a bean class and having rowSelection attribute set to "single".

e.g : rowSelection="single" binding="#{pageFlowScope.department.departmentTable}"

We will add a column in the table, which will have a command button and a actionListener mapped to bean class.

e.g : <af:column headerText="Action" id="c5">
            <af:commandButton text="Delete" id="cb1"
                              actionListener="#{pageFlowScope.department.deleteRecord}"/>
          </af:column>

Java Code snippet :

    public void deleteRecord(ActionEvent actionEvent) {
//Fetch current row data as per index
        FacesCtrlHierNodeBinding rowdata =            (FacesCtrlHierNodeBinding)departmentTable.getRowData(departmentTable.getRowIndex());
 //getting row and typecasting in RowImpl
        DeptVORowImpl rowImpl = (DeptVORowImpl)rowdata.getRow();
//Getting primary key of the record
        Number keyVal = rowImpl.getDepartmentId();
        DCBindingContainer dcBindings =
            (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
//Iterator binding on the page          
 DCIteratorBinding iteratorBinding = (DCIteratorBinding)dcBindings.get("DeptVOIterator");
        RowSetIterator rowSetIterator = iteratorBinding.getRowSetIterator();
        Key key = new Key(new Object[] { keyVal });
        Row row = rowSetIterator.findByKey(key, 1)[0];
        rowSetIterator.setCurrentRow(row);
//Removing the current record
rowSetIterator.removeCurrentRow();
}

After delete perform AM commit operation.

*Comments and feedback are most welcomed, Thanks.