Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label Set Current Date. Show all posts
Showing posts with label Set Current Date. Show all posts

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;
    }

Monday, 17 September 2018

Set current date in af:inputDate on double click using javascript in ADF

This post is about a question that is asked on the OTN forum. In this post, I'll show you how we can set the current date in af:inputDate component with a double click of the mouse. For this, we need to use a simple javascript function.



Here we have an inputDate component on the page and added javascript function as a resource in the page. See page XML source

  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
  3. xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  4. <jsp:directive.page contentType="text/html;charset=UTF-8"/>
  5. <f:view>
  6. <af:document title="SetCurrentDate.jspx" id="d1">
  7. <af:resource type="javascript">
  8. function setDate(evt) {
  9. var comp = evt.getSource()
  10. comp.setValue(new Date());
  11. }
  12. </af:resource>
  13. <af:form id="f1">
  14. <af:inputDate label="Label 1" id="id1">
  15. <af:clientListener method="setDate" type="dblClick"/>
  16. </af:inputDate>
  17. </af:form>
  18. </af:document>
  19. </f:view>
  20. </jsp:root>

All done, as you can see that the javascript function is called using clientListener on double click event of input date component.


Cheers ðŸ™‚ Happy Learning