Tuesday, December 21, 2021

Interview Questions HCL

 project and your role

taskflows - what is parent flow?

EAR and WAR deployment

EO --2 can created 1 VO

MDS -- Meta Data Services --configuration

action vs action listener

ActionListener : ActionListener is the method which got invoked when the user clicks on the component like button, CommandLink, etc

Action : Action the outcome of where you want to move once Actionlistener is completed. This can be defined in the taskflow as an activity. 

    So when listener completed application is redirected to define activity.


lifecycle

Oracle ADF architecture : Oracle ADF is based on the Model-View-Controller (MVC) design pattern.

An MVC application is separated into:
1) A model layer that handles interaction with data-sources and runs the business logic,
2) A view layer that handles the application user interface, and
3) A controller that manages the application flow and acts as the interface between the Model and the View layers.

The Oracle ADF architecture is based on four layers:

• The Business Services layer - provides access to data from various sources and handles business logic. (EJB, Web Services, ADF BC, .xml Bean definition file)
• The Model layer - provides an abstraction layer on top of the Business Services layer, enabling the View and Controller layers to work with different implementations of Business Services in a consistent way. (.cpx, .dcx, .xml)
• The Controller layer - provides a mechanism to control the flow of the Web application.
• The View layer - provides the user interface of the application. (VO files (__vo.xml), .java, .jsp, .jspx, .uix)

auto submit

nested app modules

ADF Security

jazn-data.xml



Stored proc

functions

diff b/w func and proc

triggers

dodml()

serialization

linked list?

Linked List is a part of the Collection framework present in java.util package. This class is an implementation of the LinkedList data structure which is a linear data structure where the elements are not stored in contiguous locations and every element is a separate object with a data part and address part. The elements are linked using pointers and addresses. Each element is known as a node. 

Diff b/w hashmap and set?

HashSet is an implementation of Set Interface which does not allow duplicate value. The main thing is, objects that are stored in HashSet must override equals() for check for equality, and hashCode() methods for no duplicate value are stored in our set. 

HashMap is an implementation of Map Interface, which maps a key to value. Duplicate keys are not allowed in a Map. Basically, Map Interface has two implementation classes HashMap and TreeMap the main difference is TreeMap maintains an order of the objects but HashMap will not.HashMap allows null values and null keys. Both HashSet and HashMap are not synchronized.

Exception handling in adf


1. How to get VO in backing bean?

   a) From AM

    public static AppModuleAMImpl getAM() {

        BindingContext bc = BindingContext.getCurrent();

        DCDataControl dc = bc.findDataControl("AppModuleAMDataControl");

        AppModuleAMImpl am = (AppModuleAMImpl)dc.getApplicationModule();

        return am;

    }


        ViewObject vo1 = ReusableMethodsClassPos.getAM().findViewObject("PosDeliveryDtl2");

        Row r = vo1.getCurrentRow();

   b) From Iterator

        DCBindingContainer bindings = (DCBindingContainer)resolveExpression("#{pageFlowScope.ptBindingContext}");

        //DCIteratorBinding iterator = bindings.findIteratorBinding(iteratorName);

        String vo_itr1 = (String)resolveExpression(iteratorName);

        DCIteratorBinding dcItteratorBindings = bindings.findIteratorBinding(vo_itr1);

        ViewObject vo = dcItteratorBindings.getViewObject();


        return vo;

2. Difference between Backing bean and Managed bean?


3. How to detect hostname?

public static String getClientIpAddress() {

String ip = null;

FacesContext facesContext = FacesContext.getCurrentInstance();

ExternalContext ectx = facesContext.getExternalContext();

HttpServletRequest request = (HttpServletRequest)ectx.getRequest();

String cIp = request.getRemoteAddr();

System.out.println("---Client Ip---:" + cIp);

System.out.println("-----" + request.getHeader("user-agent"));

/* try {

InetAddress ipAddr = InetAddress.getLocalHost();

ip = ipAddr.getHostAddress();

System.out.println(ip);

} catch (UnknownHostException ex) {

ex.printStackTrace();

} */

return cIp;

}


public static String getClientHostName() {

/* String hostr =

((HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest()).getRemoteHost();

System.out.println("---Client Hostname---:" + hostr); */


InetAddress ip = null;

String hostname = null;

try {

ip = InetAddress.getLocalHost();

hostname = ip.getHostName();

} catch (UnknownHostException e) {

e.printStackTrace();

}

System.out.println("hostname:" + hostname);

return hostname;

}

4. Difference between Binding Container vs Binding Context?

Binding Context is basically a map between data controls and page definition (contain bindings information) of pages in the application. Whenever an adf client or controller initiates an interaction with the business service, it(the interaction) is managed by the application through a single object. This object is the Binding Context.

Binding Container is used to instantiate page bindings. it contains bindings , executables and datacontrol mappings.

5.




Friday, December 3, 2021

ADF: Move using Tab key in AF:Table

 Problem description: Let say we have a af:table, which has some editable columns. We can use tab keys to move between these editable fields. Normal tab key moves horizontally first in same row and if there is no more editable item in row, it will jump to next row. Problem is when it jumps to new row, it does not make that row current. Now if you edit the value and have a value change listener, you may not get correct row in model.

To demonstrate the problem let us create following objects
1. Updateable EmpEO/EmpVO/EmployeeAM in our model project. EO can be based on Employee table of HR schema.
2. Drag and drop EmpVO on a jspx page (say ADFTableTabNavigation.jspx) and create a af:table. Make EmployeeId outputtext and first-name, last-name, email as editable input-text.
3. Have a bean say ADFTableTabNavigationBean.
4. Bind table with bean (say #{backingBeanScope.ADFTableTabNavigationBean.employeeTable})
3. Have auto-submit and value-change-listener on first-name, which executes a bean method (say method changeFirstName)
4. changeFirstName code should look like
    public void changeFirstName(ValueChangeEvent valueChangeEvent) {
        // Add event code here...
        String newValue = valueChangeEvent.getNewValue().toString();
        System.out.println("New First Name: " + newValue);
        JUCtrlHierBinding adfModel = (JUCtrlHierBinding)((CollectionModel)getEmployeeTable().getValue()).getWrappedData();
        DCIteratorBinding dciter = adfModel.getDCIteratorBinding();
        NavigatableRowIterator nav=dciter.getNavigatableRowIterator();
        Row row = nav.getCurrentRow();
        System.out.println("EmployeeId modified: " + row.getAttribute("EmployeeId"));
        
    }

Whenever you change first name bean method is going to print, new value of first name and employeeid or row, which is modified.

Now with this let us run our page.

Here is the behaviour that we notice.
1. If I select a row first using mouse and then change first name, it correctly prints new value and empolyeeid.
2. If I am on row1 (say employee id = 100) and then use tab key to move. Once I reach to next row (say employeeid=101), framework does not change current row. If I edit first-name, bean prints new-value of first name correctly but employeeid incorrectly. It shows employeeid of previous row (100).

At times this behaviour can lead to unexpected results because our model codes getCurrentRow will return wrong row, which is not modified. To correct it I tried following approach.

Solution:

To solve this problem we just need two steps
1. Add a custom attribute with input-text FirstName.
2. Change current-row of table before doing any processing.

--------------------------------------------------------------------------------------------------------------

1. Add a custom attribute with input-text FirstName: For this just add below code in your FirstName input text.
<af:inputText value="#{row.bindings.FirstName.inputValue}"
                          label="#{bindings.EmpVO.hints.FirstName.label}"
                          required="#{bindings.EmpVO.hints.FirstName.mandatory}"
                          columns="#{bindings.EmpVO.hints.FirstName.displayWidth}"
                          maximumLength="#{bindings.EmpVO.hints.FirstName.precision}"
                          shortDesc="#{bindings.EmpVO.hints.FirstName.tooltip}"
                          id="it2" autoSubmit="true"
                          valueChangeListener="#{backingBeanScope.ADFTableTabNavigationBean.changeFirstName}">
              <f:validator binding="#{row.bindings.FirstName.validator}"/>
              <f:attribute name="rowKey" value="#{row.EmployeeId}"/>
            </af:inputText>

This code adds a custom attribute in your input text, which holds the value of employeeid. Which means all first name input text in table actually has an attribute (rowKey), which is holding value of employeeid. Anytime if I get hold of inputtext component, I can get value of employeeid associated with it.


2. Change current-row of table before doing any processing: Now in bean method write a new mothod makeRowCurrent as shown below
    private void makeRowCurrent(ValueChangeEvent valueChangeEvent){
        oracle.jbo.domain.Number employeeId = (oracle.jbo.domain.Number)valueChangeEvent.getComponent().getAttributes().get("rowKey");
        JUCtrlHierBinding adfModel = (JUCtrlHierBinding)((CollectionModel)getEmployeeTable().getValue()).getWrappedData();
        DCIteratorBinding dciter = adfModel.getDCIteratorBinding();
        NavigatableRowIterator nav=dciter.getNavigatableRowIterator();
        Object[] objKey = new Object[1];
        objKey[0] = employeeId;
        Key key = new Key(objKey);
        nav.setCurrentRow(nav.getRow(key));
    }

You can change above method if you have different datatype of primary key or if you have composite key as primary key.

Now just call this method from your valuechangelistener
    public void changeFirstName(ValueChangeEvent valueChangeEvent) {
        // Add event code here...
        String newValue = valueChangeEvent.getNewValue().toString();
        System.out.println("New First Name: " + newValue);
        makeRowCurrent(valueChangeEvent);
        JUCtrlHierBinding adfModel = (JUCtrlHierBinding)((CollectionModel)getEmployeeTable().getValue()).getWrappedData();
        DCIteratorBinding dciter = adfModel.getDCIteratorBinding();
        NavigatableRowIterator nav=dciter.getNavigatableRowIterator();
        Row row = nav.getCurrentRow();
        System.out.println("EmployeeId modified: " + row.getAttribute("EmployeeId"));
        
    }

3. Run application and test it: You will find that you can successfully navigate using tab key and whenever you change first name, you get correct employeeid as current row.


--------------------------------------------------------------------------------------------------------------------
Effectively what we are doing: We are associating a custom attribute (rowKey) with all input-text (firstname). This custom attribute holds the value of row's primary key (employeeid). In makeRowCurrent method we try to get hold of inputtext and its corresponding custom attribute (rowKey). We construct key using employeeid and setcurrentrow using that key. Once current row is set correctly we can always know which employee record is actually modified by end user.

NOTE:
1. I searched over net and found that there could be other solutions also like handling tabkey client event and then making row current. I found it a bit too much of work to resolve simple issue.
2. One issue with this approach is that when you switch between rows, you are not making row current. We only make row current if we try to edit a field (firstname). If I don't edit field and try to navigate between rows, my current row still remains old row. I believe that is good only because if I try to to make row current every time I reach to a new row using tab, I need to unnecessary fire client event (tab key) and server event even though there is effectively no change. This will slow down tab navigation.
3. If you have composite key as primary key, you can change makeRowCurrent method as
private void makeRowCurrent(ValueChangeEvent valueChangeEvent){
        oracle.jbo.domain.Number key1 = (oracle.jbo.domain.Number)valueChangeEvent.getComponent().getAttributes().get("rowKey1");
oracle.jbo.domain.Number key2 = (oracle.jbo.domain.Number)valueChangeEvent.getComponent().getAttributes().get("rowKey2");
oracle.jbo.domain.Number key3 = (oracle.jbo.domain.Number)valueChangeEvent.getComponent().getAttributes().get("rowKey3");
        JUCtrlHierBinding adfModel = (JUCtrlHierBinding)((CollectionModel)getEmployeeTable().getValue()).getWrappedData();
        DCIteratorBinding dciter = adfModel.getDCIteratorBinding();
        NavigatableRowIterator nav=dciter.getNavigatableRowIterator();
        Object[] objKey = new Object[3];
        objKey[0] = key1;
        objKey[1] = key2;
        objKey[2] = key3;
        Key key = new Key(objKey);
        nav.setCurrentRow(nav.getRow(key));
    }

4. valueChangeEvent.getComponent().processUpdate() does not change current row so that approach does not work here.


That's it.

Friday, June 18, 2021

Date format convesrions

     public void reversalDateVCE(ValueChangeEvent vce) {

           vce.getComponent().processUpdates(FacesContext.getCurrentInstance());

           try {

               Row rHdr = CommonCode.getCurrentRowByIteratorName("FaTransHdr1Iterator");

               oracle.jbo.domain.Date vchDT = (oracle.jbo.domain.Date)rHdr.getAttribute("VchDt");

               oracle.jbo.domain.Date reversalDT = (oracle.jbo.domain.Date)rHdr.getAttribute("AutoReversalDt");

               /* oracle.jbo.domain.Date thirtyDaysAfter = CommonCode.addDayToOracleDate(vchDT, 30);

              // SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/YYYY");

               System.out.println("reversaldt@ : " + reversalDT + " thirtyDaysAfter: " + thirtyDaysAfter);


               java.util.Date vchDTUtil = CommonCode.convertOracleDateToJavaUtilDate(vchDT);

               java.util.Date thirtyDaysAfterUtil = CommonCode.convertOracleDateToJavaUtilDate(thirtyDaysAfter); */

               /* if (vchDTUtil.after(thirtyDaysAfterUtil)) {

                   CommonCode.infomsg(reversalDT + " is greater than 30 days!","");

               } */

               Long daysDiff =CommonCode.getDifferenceDaysBetweenTwoDates(reversalDT,vchDT);

               System.out.println(reversalDT+ " :reversalDT - vchDT : "+vchDT + "daysDiff = "+daysDiff);

               

               if(daysDiff > 30){

                   SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

                   java.util.Date d1 = null;

                   try {

                       d1 = sdf.parse(reversalDT.toString());


                   } catch (ParseException e) {


                       e.printStackTrace();

                   }

                   SimpleDateFormat dateFormat2 = new SimpleDateFormat("dd/MMM/yyyy");


                   String date = dateFormat2.format(d1);

                   CommonCode.infomsg(date+ " is greater than 30 days!","");

               }

           } catch (NullPointerException npe) {

               CommonCode.showExceptionMessage(npe);

           } catch (Exception e) {

               CommonCode.showExceptionMessage(e);

           }

       }

/

    //added by Naren

    public static java.util.Date convertOracleDateToJavaUtilDate(oracle.jbo.domain.Date oracleDate) {

        if (oracleDate == null)

            return null;


        java.sql.Date javaSqlDate = oracleDate.dateValue();

        long javaMilliSeconds = javaSqlDate.getTime();

        return new java.util.Date(javaMilliSeconds);

    }


    //added by Naren

    public static oracle.jbo.domain.Date addDayToOracleDate(oracle.jbo.domain.Date date, int days) {

        if (date != null) {

            Calendar c1 = Calendar.getInstance();

            c1.setTime(date.getValue());

            c1.add(Calendar.DATE, days);

            java.util.Date javaUtilDate = c1.getTime();

            long javaMilliseconds = javaUtilDate.getTime();

            java.sql.Date javaSqlDate = new java.sql.Date(javaMilliseconds);

            return new oracle.jbo.domain.Date(javaSqlDate);

        }

        return null;

    }

    

    public static long getDifferenceDaysBetweenTwoDates(oracle.jbo.domain.Date d1, oracle.jbo.domain.Date d2)

      {

        if(d1 != null && d2 != null)

        {

          return (d1.getValue().getTime() - d2.getValue().getTime())/(24 * 60 * 60 * 1000);

        }

        return 0;

      }


/

[15:57] NARENDRA ENAMALA

    public void frmDtChange(ValueChangeEvent vce) {
        Date d1;
        if(vce.getNewValue()!=null){
            d1 = (Date)vce.getNewValue();
        if (this.getId2().getValue() != null) {
            Date d2 = (Date)this.getId2().getValue();
            if (d1.getValue().after(d2.getValue())) {
                FacesContext context = FacesContext.getCurrentInstance();
                FacesMessage fm = new FacesMessage("From Date cannot be greater than To Date");
                fm.setSeverity(FacesMessage.SEVERITY_ERROR);
                context.addMessage(this.getId1().getClientId(), fm);
            }
        }
    }
    }


[15:57] NARENDRA ENAMALA

    public void toDtChange(ValueChangeEvent vce) {
        Date d1;
        if(vce.getNewValue()!=null){
            d1 = (Date)vce.getNewValue();
        if (this.getId1().getValue() != null) {
            Date d2 = (Date)this.getId1().getValue();
            if (d1.getValue().before(d2.getValue())) {
                FacesContext context = FacesContext.getCurrentInstance();
                FacesMessage fm = new FacesMessage("To Date cannot be less than From Date");
                fm.setSeverity(FacesMessage.SEVERITY_ERROR);
                context.addMessage(this.getId2().getClientId(), fm);
            }
        }
        }
    }


---- from dt and To date timestamp validations


       public void fromDateVce(ValueChangeEvent vce) {
            vce.getComponent().processUpdates(FacesContext.getCurrentInstance());
        
                /*  if (vce.getNewValue() != null) {
                
                        Row hdrRow = ReusableMethodsClass.getCurrentRowFromVO("PrCancelHdrVo1");
                        Timestamp frmDt = (Timestamp) hdrRow.getAttribute("PrFromDate");
                        Timestamp toDt = (Timestamp) hdrRow.getAttribute("PrToDate");
                
                    if (frmDt !=null && toDt != null && frmDt.compareTo(toDt)==1 ) {
                        CommonCode.errmsg("From Date should not be greater than To Date.", "");
                        return ;
                    }
                
                } */
                 oracle.jbo.domain.Date d1;
                       if(vce.getNewValue()!=null){
                      java.sql.Timestamp tmpFrom = (java.sql.Timestamp)getId1().getValue();
                       java.util.Date dateUtilFrom = new java.util.Date(tmpFrom.getTime());
                       System.out.println(vce.getNewValue()+":from vce.getNewValue() this.getId1().getValue():"+this.getId1().getValue()+" dateUtilFrom :"+dateUtilFrom);
                          d1 = (oracle.jbo.domain.Date)convertJavaUtilDateToOracleDate(dateUtilFrom); //vce.getNewValue();
                          System.out.println("from Job Domine Date D1 : "+d1);
                       if (this.getId2().getValue() != null) {
                           //oracle.jbo.domain.Date d2 = (oracle.jbo.domain.Date)this.getId2().getValue();
                           java.sql.Timestamp tmpTo = (java.sql.Timestamp)getId2().getValue();
                            java.util.Date dateUtilTo = new java.util.Date(tmpTo.getTime());
                           oracle.jbo.domain.Date d2 = (oracle.jbo.domain.Date)convertJavaUtilDateToOracleDate(dateUtilTo);
                           System.out.println("from Job Domine Date D2 : "+d2);
                           if (d1.getValue().after(d2.getValue())) {
                               FacesContext context = FacesContext.getCurrentInstance();
                               FacesMessage fm = new FacesMessage("From Date cannot be greater than To Date");
                               fm.setSeverity(FacesMessage.SEVERITY_ERROR);
                               context.addMessage(this.getId1().getClientId(), fm);
                           }
                       }
        
                   }
        }
    
    public void toDateVce(ValueChangeEvent vce) {
        vce.getComponent().processUpdates(FacesContext.getCurrentInstance());  
              oracle.jbo.domain.Date d1;
                    if(vce.getNewValue()!=null){
                        System.out.println(vce.getNewValue()+":to vce.getNewValue() this.getId2().getValue():"+this.getId2().getValue());
                       // java.sql.Date javaSqlDate = new java.sql.Date(vce.getNewValue());
                       // d1 = (oracle.jbo.domain.Date)this.getId2().getValue();
                        
                        java.sql.Timestamp tmpTo = (java.sql.Timestamp)getId2().getValue();
                         java.util.Date dateUtilTo = new java.util.Date(tmpTo.getTime());
                         System.out.println(vce.getNewValue()+":@to vce.getNewValue() this.getId1().getValue():"+this.getId1().getValue()+" dateUtilFrom :"+dateUtilTo);
                            d1 = (oracle.jbo.domain.Date)convertJavaUtilDateToOracleDate(dateUtilTo);
                            
                        System.out.println("to Job Domine Date D1 : "+d1);
                    if (this.getId1().getValue() != null) {
                       // oracle.jbo.domain.Date d2 = (oracle.jbo.domain.Date)this.getId1().getValue();
                       java.sql.Timestamp tmpFrom = (java.sql.Timestamp)getId1().getValue();
                        java.util.Date dateUtilFrom = new java.util.Date(tmpFrom.getTime());
                       oracle.jbo.domain.Date d2 = (oracle.jbo.domain.Date)convertJavaUtilDateToOracleDate(dateUtilFrom);
                        System.out.println(" @to Job Domine Date D2 : "+d2);
                        if (d1.getValue().before(d2.getValue())) {
                            FacesContext context = FacesContext.getCurrentInstance();
                            FacesMessage fm = new FacesMessage("To Date cannot be less than From Date");
                            fm.setSeverity(FacesMessage.SEVERITY_ERROR);
                            context.addMessage(this.getId2().getClientId(), fm);
                        }
                        
                         oracle.jbo.domain.Date currdate = getCurrentOracleDate();
                         System.out.println("currdate.getValue() :"+currdate.getValue()+" currdate :"+currdate);
                        if (d1.getValue().after(currdate.getValue())) {
                            FacesContext context = FacesContext.getCurrentInstance();
                            FacesMessage fm = new FacesMessage("To Date cannot be Future Date");
                            fm.setSeverity(FacesMessage.SEVERITY_ERROR);
                            context.addMessage(this.getId2().getClientId(), fm);
                        }
                    }
                    }
        
    
         
            
    }
    



   /** function receive java.util date and convert it to oracle date then return oracle date */
      public static Date convertJavaUtilDateToOracleDate(java.util.Date javaUtilDate)
      {
        if(javaUtilDate == null)
          return null;


       long javaMilliseconds = javaUtilDate.getTime();
        java.sql.Date javaSqlDate = new java.sql.Date(javaMilliseconds);
        return new oracle.jbo.domain.Date(javaSqlDate);
      }
    
    /** function will return current date as an oracle Date object */
      public static oracle.jbo.domain.Date getCurrentOracleDate()
      {
        return new oracle.jbo.domain.Date(oracle.jbo.domain.Date.getCurrentDate());
      }

/


    public static oracle.jbo.domain.Date castToJBODate(String aDate) {

        DateFormat formatter;

        SimpleDateFormat dateFormat;

        java.util.Date date;


        if (aDate != null) {


            try {


                //formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss ");

                dateFormat = new SimpleDateFormat("dd/MM/yyyy");

                //date = formatter.parse(aDate);

                date = (java.util.Date)dateFormat.parse(aDate);

                System.out.println("Sql Date:" + date.getTime() + " : " + date);

                java.sql.Date sqlDate = new java.sql.Date(date.getTime());

                java.sql.Date timestamp = new java.sql.Date(date.getTime());

                System.out.println("Date after :" + sqlDate);

                //oracle.jbo.domain.Timestamp jboDate = new oracle.jbo.domain.Timestamp(sqlDate);

                oracle.jbo.domain.Date jboDate = new oracle.jbo.domain.Date(timestamp);

                System.out.println("Jbo Date:" + jboDate);

                return jboDate;

            } catch (ParseException e) {

                e.printStackTrace();

            }


        }


        return null;

    }


    

Dealing With Dates in Java

 

Dealing With Dates in Java

Many developers sometimes face a problems when they dealing with dates. In java there are many types of dates as:

- java.util.Date
- java.sql.Date
- java.sql.Timestamp
- oracle.jbo.domain.Date
- oracle.jbo.domain.Timestamp

ADF developers sometimes need to:

- Get current date (oracle.jbo.domain.Date or  oracle.jbo.domain.Timestamp) to set attribute in ViewObject programmatically .

- Convert between dates types.

- Add/Subtract some days from date.

- Display current date on the screen (as string) in specific format.

- Display name of current day in this week (Saturday - Sunday - ...... - Friday).

- Get current time.

- Get current day.

- Get current month.

- Get current year.

- Compare between two dates.

- Get the number of days difference between two dates.

All these previous functions developers need to know so, I made a set of functions to help developers to deal with dates.

  /** function return current date time in format (dd / MM / yyyy - HH:mm:ss) */
  public static String getDisplayedDateTime()
  {
    Calendar cal = Calendar.getInstance();
    String dateFormat = "dd / MM / yyyy - HH:mm:ss";
    SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
    return sdf.format(cal.getTime());
  }

  /** function return current date or time depending on the format which you are want. Just send a format and the function will return the current date or time depending on the 
      format which you are sent (e.g. getDisplayedDateFormat("yyyy-mm-dd") it will return 2013-11-18 */
  public static String getDisplayedDateFormat(String dateFormat)
  {
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
    return sdf.format(cal.getTime());
  }

  /** function return the index of current day in this week (if today is Sunday it will retun 1 and if the today is Monday this function will return 2 and so on... 
      till Saturday it will return 7) */
  public static int getCurrentDayOfWeek()
  {
    Calendar cal = Calendar.getInstance();
    return cal.get(Calendar.DAY_OF_WEEK);
  }

  /** function return the name of current day in this week (Saturday - Sunday - ...... - Friday) */
  public static String getCurrentDayOfWeekName()
  {
    int numberOfDay = getCurrentDayOfWeek();
    if(numberOfDay == 7)
    {
      return "Saturday";
    }
    else if(numberOfDay == 1)
    {
      return "Sunday";
    }
    else if(numberOfDay == 2)
    {
      return "Monday";
    }
    else if(numberOfDay == 3)
    {
      return "Tuesday";
    }
    else if(numberOfDay == 4)
    {
      return "Wednesday";
    }
    else if(numberOfDay == 5)
    {
      return "Thursday";
    }
    return "Friday";
  }

  /** function return current day. ( e.g. today is 2013/11/18 this function will return 18) */
  public static int getCurrentDay()
  {
    Calendar cal = Calendar.getInstance();
    return cal.get(Calendar.DAY_OF_MONTH);
  }

  /** function return current month. ( e.g. today is 2013/11/18 this function will return 11) */
  public static int getCurrentMonth()
  {
    Calendar cal = Calendar.getInstance();
    return cal.get(Calendar.MONTH) + 1;
  }

  /** function return current year. ( e.g. today is 2013/11/18 this function will return 2013) */
  public static int getCurrentYear()
  {
    Calendar cal = Calendar.getInstance();
    return cal.get(Calendar.YEAR);
  }

  /** function will return current date as an oracle Date object */
  public static oracle.jbo.domain.Date getCurrentOracleDate()
  {
    return new oracle.jbo.domain.Date(oracle.jbo.domain.Date.getCurrentDate());
  }

  /** function will return current date and time as an oracle Date object */
  public static oracle.jbo.domain.Date getCurrentOracleDateTime()
  {
    return new oracle.jbo.domain.Date(new java.sql.Timestamp(System.currentTimeMillis()));
  }

  /** function will return current date and time as an oracle Timestamp object */
  public static oracle.jbo.domain.Timestamp getCurrentOracleTimestampDateTime()
  {
    return new oracle.jbo.domain.Timestamp(new java.util.Date().getTime());
  }

  /** function will return current time */
  public static String getCurrentTime()
  {
    return  getDisplayedDateFormat("HH:mm");
  }

  /** function receive oracle date and return true or false (if sent date greater than current date it will return true 
      but if sent date less than or equal current date it will return false */
  public static boolean isDateGreaterThanCurrentDate(oracle.jbo.domain.Date d)
  {
    if(d == null)
      return false;
 
    oracle.jbo.domain.Date currentDate = new oracle.jbo.domain.Date(oracle.jbo.domain.Date.getCurrentDate());
    if(d.compareTo(currentDate) > 0)
      return true;
 
    return false;
  }

  /** function receive two oracle dates and return true or false (if first date greater than second date it will return true 
      but if first date less than or equal second date it will return false */
  public static boolean isFirstDateGreaterThanSecondDate(oracle.jbo.domain.Date d1, oracle.jbo.domain.Date d2)
  {
    if(d1 == null && d2 == null)
      return false;
 
    if(d1 == null && d2 != null)
      return false;
 
    if(d1 != null && d2 == null)
      return true;
 
    if(d1.compareTo(d2) > 0)
      return true;
 
    return false;
  }

  /** function receive three oracle dates and return true or false (if first date greater than or equal second date and first date less than or equal third date it will return true. 
      otherwise it will return false */
  public static boolean isFirstDateBetweenTwoDates(oracle.jbo.domain.Date d1, oracle.jbo.domain.Date d2, oracle.jbo.domain.Date d3)
  {
    if(d1 == null || d2 == null || d3 == null)
      return false;
 
    if(d1.compareTo(d2) >= 0 && d1.compareTo(d3) <= 0)
      return true;
 
    return false;
  }

  /** function receive date and integer then add the integer to the date then return the result date.
      (e.g. if you send 2013/07/13 and 5 to this function the function will return 2013/07/18 */
  public static Date addDayToOracleDate(oracle.jbo.domain.Date date, int days)
  {
    if (date != null)
    {
      Calendar c1 = Calendar.getInstance();
      c1.setTime(date.getValue());
      c1.add(Calendar.DATE, days);
      java.util.Date javaUtilDate = c1.getTime();
      long javaMilliseconds = javaUtilDate.getTime();
      java.sql.Date javaSqlDate = new java.sql.Date(javaMilliseconds);
      return new oracle.jbo.domain.Date(javaSqlDate);
    }
    return null;
  }

  /** function receive two oracle dates then return the number of days difference between them. (e.g. if you send 2013/07/20 , 2013/07/13 to the function the function will return 7 */
  public static long getDifferenceDaysBetweenTwoDates(oracle.jbo.domain.Date d1, oracle.jbo.domain.Date d2)
  {
    if(d1 != null && d2 != null)
    {
      return (d1.getValue().getTime() - d2.getValue().getTime())/(24 * 60 * 60 * 1000);
    }
    return 0;
  }

  /** function receive oracle date and convert it to java.util date then return java.util date */
  public static java.util.Date convertOracleDateToJavaUtilDate(oracle.jbo.domain.Date oracleDate)
  {
    if(oracleDate == null)
      return null;
 
    java.sql.Date javaSqlDate = oracleDate.dateValue();
    long javaMilliSeconds = javaSqlDate.getTime();
    return new java.util.Date(javaMilliSeconds);
  }

  /** function receive oracle date and convert it to java.sql date then return java.sql date */
  public static java.sql.Date convertOracleDateToJavaSqlDate(oracle.jbo.domain.Date oracleDate)
  {
    if(oracleDate == null)
      return null;
 
    return oracleDate.dateValue();
  }

  /** function receive java.util date and convert it to oracle date then return oracle date */
  public static Date convertJavaUtilDateToOracleDate(java.util.Date javaUtilDate)
  {
    if(javaUtilDate == null)
      return null;
 
    long javaMilliseconds = javaUtilDate.getTime();
    java.sql.Date javaSqlDate = new java.sql.Date(javaMilliseconds);
    return new oracle.jbo.domain.Date(javaSqlDate);
  }

  /** function receive java.sql date and convert it to oracle date then return oracle date */
  public static Date convertJavaSqlDateToOracleDate(java.sql.Date javaSqlDate)
  {
    if(javaSqlDate == null)
      return null;
 
    return new oracle.jbo.domain.Date(javaSqlDate);
  }

  /** function receive java.util date and convert it to java.sql date then return java.sql date */
  public static java.sql.Date convertJavaUtilDateToJavaSqlDate(java.util.Date javaUtilDate)
  {
    if(javaUtilDate == null)
      return null;
 
    long javaMilliseconds = javaUtilDate.getTime();
    return new java.sql.Date(javaMilliseconds);
  }

  /** function receive java.sql date and convert it to java.util date then return java.util date */
  public static java.util.Date convertJavaSqlDateToJavaUtilDate(java.sql.Date javaSqlDate)
  {
    if(javaSqlDate == null)
      return null;
 
    long javaMilliseconds = javaSqlDate.getTime();
    return new java.util.Date(javaMilliseconds);
  }


public static String dateToStrig(String d){
        SimpleDateFormat sdf =     new  SimpleDateFormat("yyyy-MM-dd");
          Date d1=null;
          try {
              d1 = sdf.parse(d);
          } catch (ParseException e) {
              e.printStackTrace();
          }
        System.out.println(d1);
          SimpleDateFormat sdff = new SimpleDateFormat("dd-MM-yyyy");
          String date1 = sdff.format(d1);
          return date1;
    }

Latest Date conversion///
    /** function receive java.util date and convert it to oracle date then return oracle date */
    public oracle.jbo.domain.Date convertJavaUtilDateToOracleDate(java.util.Date javaUtilDate) {
        if (javaUtilDate == null)
            return null;

        long javaMilliseconds = javaUtilDate.getTime();
        java.sql.Date javaSqlDate = new java.sql.Date(javaMilliseconds);
        return new oracle.jbo.domain.Date(javaSqlDate);
    }

    /** function will return current date as an oracle Date object */
    public oracle.jbo.domain.Date getCurrentOracleDate() {
        return new oracle.jbo.domain.Date(oracle.jbo
                                                .domain
                                                .Date
                                                .getCurrentDate());
    }

    public java.util.Date convertStringToUtilDate(String dt) {
        SimpleDateFormat DateFor = new SimpleDateFormat("dd-MMM-yyyy");
        java.util.Date utilDate = null;
        try {
            utilDate = DateFor.parse(dt);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return utilDate;
    }

    /** function receive two oracle dates then return the number of days difference between them. (e.g. if you send 2013/07/20 , 2013/07/13 to the function the function will return 7 */
    public long getDifferenceDaysBetweenTwoDates(oracle.jbo.domain.Date d1, oracle.jbo.domain.Date d2) {
        if (d1 != null && d2 != null) {
            return (d1.getValue().getTime() - d2.getValue().getTime()) / (24 * 60 * 60 * 1000);
        }
        return 0;
    }
    
    public oracle.jbo.domain.Date convertJavaSqlDateToOracleDate(java.sql.Date javaSqlDate)
      {
        if(javaSqlDate == null)
          return null;
     
        return new oracle.jbo.domain.Date(javaSqlDate);
      }
    
    public java.util.Date convertSqlTimestampToUtilDate(java.sql.Timestamp sqlTimestamp){
    java.sql.Timestamp ts=sqlTimestamp;  
    java.util.Date date=ts;  
    return  date;            
    }  

    public oracle.jbo.domain.Date convertJavaSqlTimestampToOracleDate(java.sql.Timestamp javaSqlDate)
      {
        if(javaSqlDate == null)
          return null;
     
        return new oracle.jbo.domain.Date(javaSqlDate);
      }

Tuesday, January 26, 2021

How to remove "Query By Example" feature from Panel collection(ADF Table)

Sometimes, we may do not want to "Query By Example" feature provided by panel collection in Oracle ADF.


If you want to hide / remove it, then do as mentioned below.

Remove these attributes from the panel collection

filterModel="#{bindings.TestVO1Query.queryDescriptor}"
                  queryListener="#{bindings.TestVO1Query.processQuery}"
                  filterVisible="true"

Hope this helps!.