Wednesday 8 August 2018

Display Current Date on OAF Page


Do Controller Extension and use below working code snippet in controller.

In Controller processRequest

// Show Current date on Page

        OAMessageDateFieldBean currentdate = // no need to specify a data type
            // always specify name
            (OAMessageDateFieldBean)createWebBean(pageContext,
                                                  OAWebBeanConstants.MESSAGE_DATE_FIELD_BEAN,
                                                  null, "datefield");
        currentdate.setReadOnly(true);
        pageLayoutBean.addIndexedChild(currentdate);




        OAApplicationModule am = pageContext.getApplicationModule(webBean);
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String dateString =
            am.getOADBTransaction().getCurrentDBDate().toString();


        java.sql.Date sqlDate = null;


        try {
            sqlDate = new Date(f.parse(dateString).getTime());
            System.out.println("What is sqlDate value ********** " + sqlDate);
        } catch (ParseException e) {
            e.getMessage();


        }
        OAMessageDateFieldBean dateField =
            (OAMessageDateFieldBean)webBean.findIndexedChildRecursive("datefield");
        if (dateField != null) {
            dateField.setValue(pageContext, sqlDate);
            System.out.println("I am checking dateField  not null ********* " + dateField );
        }