Anil's Blog is Best Viewed on GOOGLE CHROME

Please contact us for Off-shore projects, Online Trainings and any kind of Operational & Support issues

Sunday, August 31, 2014

Find Duplicate Row OR Copy/Clone VO Row

This article will give you idea on how to restrict user to enter duplicate rows. The requirement came when we want to enhance the user experience by providing the functionality to allow multiple Tools issue at one time.

This is applicable to all pages having table region/ advance table region and you want to restrict the user from enetring duplicate row. Here please keep in mind that I am not comparing the VO rows with DB rows. 

Application Module Method

        public void checkDuplicateRow() {

        XxTestToolsVOImpl lo_tools = getXxTestToolsVO(); //Table View Object
        XxTestToolsVOImpl clonevo = 
            (XxTestToolsVOImpl)this.findViewObject("XxTestToolsVO2"); //Dummy VO for check duplicity 
        if (clonevo == null) {
   //Create Dummy VO
            clonevo = 

        Row[] sourceVORows = 
            lo_tools.getFilteredRows("SelectFlag", "Y"); //Picking only those row where the Checkbox is checked
        if (!(clonevo.isPreparedForExecution())) {
  //Create ClonveVO with SourceVO rows
        for (Row row: sourceVORows) {
            Row cloneRow = clonevo.createRow();
            cloneRow = row;
            clonevo.insertRowAtRangeIndex(clonevo.getRangeIndexOf(clonevo.last()) + 
                                          1, cloneRow);//Inserting row one after another
        int i = 0;
        int j;
   for (Row row: sourceVORows) {
                j = 0;
                for (clonevo.first(); j < clonevo.getFetchedRowCount(); 
                    if (i == j) {
                        continue; //Ignore the row where index is same.
// This loop compare 1st row with all the rows except 1st then second row will   all the rows except 2nd and so on.
        if ((row.getAttribute("SerialNumber") +"").equals((clonevo.getCurrentRow().getAttribute("SerialNumber"))+"") && (row.getAttribute("InventoryItemId") + "").equals((clonevo.getCurrentRow().getAttribute("InventoryItemId"))+"") && (row.getAttribute("LotNumber") + "").equals((clonevo.getCurrentRow().getAttribute("LotNumber")) +  "") && (row.getAttribute("SubinventoryCode") +  "").equals((clonevo.getCurrentRow().getAttribute("SubinventoryCode")) + "") &&  (row.getAttribute("Locator") + "").equals((clonevo.getCurrentRow().getAttribute("Locator")) + ""))
                  clonevo.remove(); //If the row is duplicate remove the dummy VO
                  throw new OAException("Row Number " + (i + 1) + " and " + (j + 1) + " is duplicate." + " Please select only unique Tools to issue");

Thanks, --Anil

Sunday, July 20, 2014

Setting WHO columns in OAF & setting date in custom table

import java.text.SimpleDateFormat;
import java.sql.PreparedStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Timestamp;

Application Module Code

    public void SettingWhoColumns(String CStringDate) {
        java.sql.Date ConvStringDate = null;
        try {
            Connection conn = getOADBTransaction().getJdbcConnection();

            String Query = 
                "insert into XX_INSERT_WHO_COLUMNS  CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, LAST_UPDATED_BY, LAST_UPDATE_LOGIN) values (:1, :2, :3, :4 ,:5)";
            PreparedStatement stmt = conn.prepareStatement(Query);
            //Creation Date
            stmt.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
            stmt.setInt(2, getOADBTransaction().getUserId()); // Created by
            //Last update date 
            stmt.setTimestamp(3, new Timestamp(System.currentTimeMillis()));
            stmt.setInt(4, getOADBTransaction().getUserId()); // Last updated by
            stmt.setInt(5,getOADBTransaction().getLoginId()); // Last updated login
            //Who columns setting end here.....

            // Getting Date as a String, Converting it to Date format and setting it
            if (CStringDate != null & !("".equalsIgnoreCase(CStringDate))) {
                SimpleDateFormat dtformatter = 
                    new SimpleDateFormat("dd-MMM-yyyy");
                ConvStringDate = 
                        new java.sql.Date(dtformatter.parse(CStringDate).getTime());
            stmt.setDate(6, ConvStringDate);
        } catch (Exception e) {
            throw new OAException("Exception" + e);


Friday, April 25, 2014

Make OAF page readonly

In the Controller process request method just write the below code to make whole page read only in one go.

import com.oaframework.toolkit.util.WebBeanUtil;

    public void processRequest(OAPageContext pageContext, OAWebBean webBean) {
        super.processRequest(pageContext, webBean);
     // this class loops all the webbean hierarchy and make read only each and even bean and also sets the CSS accordingly.

      WebBeanUtil.setViewOnlyRecursive(pageContext, webBean);

In case of you are not able to get the WebBeanUtil file then please mail me I will provide you.