Please disable your adblock and script blockers to view this page

Search this blog

Thursday, 7 November 2024

Working with Dates in Oracle ADF and Java

Get Current JBO Date with Time 



Sometimes we need to get and set the current date in our Oracle ADF code

To get the current date in an Oracle ADF application using oracle.jbo.domain.Date, we can use this code, this code can be written in model implementation classes or in Managed Bean





 /**Method to get current JBO Date with time part
     * @return
     */
    public Date getCurrentJboDate(){
        Date currentDate = (Date) Date.getCurrentDate();
        return currentDate;
    }



Get the current JBO Date in a Specific format


There are times when you need to work with just the date and not the time, whether it's for formatting purposes or for cleaner data extraction. In such cases, you can use a simple code snippet to retrieve the date in a specific format. Here's how you can do it!

    /**Method to get current JBO Date in Specific format
     * @return
     */
    public Date getformattedJboDate() {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MMM-dd");
        java.util.Date date = new java.util.Date();
        String date1 = dateFormat.format(date);
        try {
            date = dateFormat.parse(date1);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        
        java.sql.Date sqlDate = new java.sql.Date(date.getTime());
        oracle.jbo.domain.Date formattedDate = new oracle.jbo.domain.Date(sqlDate);
        return formattedDate;
    }

Saturday, 28 September 2019

Oracle ADF and JDeveloper 12.2.1.4 Are Available

Finally some good news for Oracle ADF Community :)

Director of Product Management Shay Shmeltzer has posted a blog about new realse of Oracle ADF and Jdeveloper 12.2.1.4

Oracle JDeveloper and Oracle ADF 12.2.1.4 Now Available

List of new features - Oracle ADF 12.2.1.4 new features

List of fixed bugs - List of fixed bugs

Download and let us know about your experience



Monday, 27 May 2019

Oracle JET Common Model Factory Method to Consume REST Services

 Previously I have posted about consuming web services in Oracle JET using jQuery method and using Oracle JET Common Model. I have seen the Oracle JET Common Model Factory method in one of the blog and in MOOC course so tried the same but because of some version change or problem it was not working as expected but I got a solution in the OTN JET forum and sharing same here for reference.



Here I am using the same JET nav drawer template application that is used in my first post – Using Oracle JET with JDeveloper. and using ADF BC based REST web service

Add an oj-table component in the dashboard.html page and define the required number of columns to show Departments details.

  1. <div class="oj-hybrid-padding">
  2. <h1>Dashboard Content Area</h1>
  3. <div id="div1">
  4. <oj-table id="table" summary="Department List"
  5. aria-label="Departments Table"
  6. data='[[datasource]]'
  7. columns='[{"headerText": "Department Id",
  8. "field": "DepartmentId"},
  9. {"headerText": "Department Name",
  10. "field": "DepartmentName"},
  11. {"headerText": "Location Id",
  12. "field": "LocationId"},
  13. {"headerText": "Manager Id",
  14. "field": "ManagerId"}]'>
  15. </oj-table>
  16. </div>
  17. </div>

Next is to create a Factory JS file that holds the basic code for calling web service and read its response (Oracle JET Common Model and Collection is used in a separate file for better understanding of code )



Here goes the code for DeptFactory.js

  1. define(['ojs/ojcore'], function (oj) {
  2. var DeptFactory = {
  3. resourceUrl : 'http://127.0.0.1:7101/RestWebServApp-RESTWebService-context-root/rest/Jdev12.2.1/Department',
  4. // Single Department Model
  5. createDeptModel : function () {
  6. var dept = oj.Model.extend( {
  7. urlRoot : this.resourceUrl,
  8. idAttribute : "DepartmentId"
  9. });
  10. return new dept();
  11. },
  12. // Departments Collection
  13. createDepartmentsCollection : function () {
  14. var departments = oj.Collection.extend( {
  15. url : this.resourceUrl,
  16. model : this.createDeptModel(),
  17. comparator : "DepartmentId"
  18. });
  19. return new departments();
  20. }
  21. };
  22. return DeptFactory;
  23. });

And this Factory JS is used in dashboard.js View Model to populate data in the JET table

  1. /**
  2. * @license
  3. * Copyright (c) 2014, 2019, Oracle and/or its affiliates.
  4. * The Universal Permissive License (UPL), Version 1.0
  5. */
  6. /*
  7. * Your dashboard ViewModel code goes here
  8. */
  9. define(['ojs/ojcore', 'knockout', 'jquery', 'DeptFactory', 'ojs/ojtable', 'ojs/ojcollectiontabledatasource'],
  10. function (oj, ko, $, DeptFactory) {
  11. function DashboardViewModel() {
  12. var self = this;
  13. self.deptCollection = DeptFactory.createDepartmentsCollection();
  14. self.datasource = ko.observable()
  15. // Setting collection in row and column format to show in JET table
  16. self.datasource(new oj.CollectionTableDataSource(this.deptCollection));
  17. }
  18. return new DashboardViewModel;
  19. });

Now run application and check, Department details are populated in the table from web service



So this is how we can use the Oracle JET Common Model Factory method to consume REST web services.

Cheers 🙂 Happy Learning