ads

X

Wednesday, March 26, 2014

Show current Date and Time on Page in Oracle ADF (refresh Date/time Programmatically)

This tutorial i am going to explain that how to show current date and time on your ADF application page
Follow Steps-

  • Create a fusion web application and a page in it (i have used .jspx page)
  • Now drag an output text from component palette and drop it on page

  • Now select the output text and go to its property inspector then select value from Expression Builder as shown in image
  • Now in Expression Builder ,create a Managed Bean of type java.util.Date and assign its value to output text

  •  Now run your page and see current date is there
  • Now to format Date and Time , drag and drop af:convertDateTime  under output text from component palette



  •  Select convertDateTime and go to property inspector and change its pattern and run your page


  •  Now you have done basic configuration for Date/Time, if you want to refresh time (second and minute part) on page periodically then drop a poll component in page and create a poll listener in managed bean
  • Now write this simple code in your managed bean to invoke poll listener

  •     /**Binding of Output text*/
        private RichOutputText dateBind;
    
        public void setDateBind(RichOutputText dateBind) {
            this.dateBind = dateBind;
        }
    
        public RichOutputText getDateBind() {
            return dateBind;
        }
    
        protected void refreshPage() {
            FacesContext fctx = FacesContext.getCurrentInstance();
            String refreshpage = fctx.getViewRoot().getViewId();
            ViewHandler ViewH = fctx.getApplication().getViewHandler();
            UIViewRoot UIV = ViewH.createView(fctx, refreshpage);
            UIV.setViewId(refreshpage);
            fctx.setViewRoot(UIV);
        }
    
    
        /**Poll Listener Method ,handles Poll Event
         * @param pollEvent
         */
        public void refreshTime(PollEvent pollEvent) {
            refreshPage();
            AdfFacesContext.getCurrentInstance().addPartialTarget(dateBind);
    
        }
    

  • Now Run your application , see in this video clip how your page get refreshed... Cheers ..!
  •