Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label How to. Show all posts
Showing posts with label How to. Show all posts

Tuesday 6 May 2014

ADF Basics : Selecting and showing time-stamp in ADF Faces using af:inputDate & af:convertDateTime

Hello All
This post is about a very common & basic requirement of developers ,
how to show & select time with date in ADF Faces ?
We use af:inputDate to show and select Date & Timestamp type of attributes, by default it looks like this



ADF provides a default converter (af:convertDateTime) to format date & timestamp field, we can define a pattern to change it's format & to show time selector in calendar box



Suppose pattern is- dd-MMM-yyy HH:mm:ss , now see there is a hour/minute/second selector appears in calendar box



you can change this pattern as per your format , suppose you want to show AM or PM after time just use dd-MMM-yyy HH:mm:ss a



see xml source of af:inputDate-


<af:inputDate label="Label 1" id="id1" contentStyle="width:250px;padding:5px;">
                        <af:convertDateTime pattern="dd-MMM-yyy HH:mm:ss a"/>
                    </af:inputDate>

this is how we can change format of Date & Timestamp - Cheers :-)

Wednesday 5 June 2013

Download file from url using Oracle ADF & Java- Download Manager

In this tutorial i will show you how to download a file from its url (web)-
as- http://www.tutorialspoint.com/java/java_tutorial.pdf
This will work as a simple download manager, you can add file url to download it and save it.
This tutorial makes use of FileHandling and java.net.URL class in java.

  • User Interface is very simple to design as it have only one input text and one button, so create a fusion web application , and a bounded taskflow with a page fragment in it
  • Now drag a Input text to enter url and a button to perform action on it from Componenet palette .
  • Bind input text to bean to get its value from page

  •  private RichInputText fileUrlBind;
    
        public void setFileUrlBind(RichInputText fileUrlBind) {
            this.fileUrlBind = fileUrlBind;
        }
    
        public RichInputText getFileUrlBind() {
            return fileUrlBind;
        }
    
  • Now create actionListener to managed bean and write code for downloading file from given url- see code

  •     public void DownloadFileButton(ActionEvent actionEvent) {
            try {
                if (fileUrlBind.getValue() != null) {
                    String fileUrl = fileUrlBind.getValue().toString();
                    if (fileUrl.startsWith("http://")) {
                        String msgNm = fileUrl.substring(7);
    
                        cnctmsgBind.setValue("Connecting to " + msgNm + "....");
    
                        URL url = new URL(fileUrl);
                        url.openConnection();
                        InputStream reader = url.openStream();
    
    
                        FileOutputStream writer =
                            new FileOutputStream("C:/javadrive." + fileUrl.substring(fileUrl.lastIndexOf(".")));
                        byte[] buffer = new byte[153600];
                        int totalBytesRead = 0;
                        int bytesRead = 0;
    
                       
                        dwnldMsgBind.setValue("Reading file 150KB blocks at a time");
                        while ((bytesRead = reader.read(buffer)) > 0) {
                            writer.write(buffer, 0, bytesRead);
                            buffer = new byte[153600];
                            totalBytesRead += bytesRead;
                        }
                     
                        alerMsgBind.setValue("File is downloaded successfully, look at your c drive :-)");
                        writer.close();
                        reader.close();
                    } else {
                        FacesMessage errMsg = new FacesMessage("Something went wrong");
                        errMsg.setSeverity(FacesMessage.SEVERITY_ERROR);
                        errMsg.setDetail("Example- http://www.javadrive.co.in/java.pdf");
                        FacesContext context = FacesContext.getCurrentInstance();
                        context.addMessage(fileUrlBind.getClientId(), errMsg);
                    }
                }
            } catch (MalformedURLException e) {
                FacesMessage errMsg = new FacesMessage("Something went wrong");
                errMsg.setSeverity(FacesMessage.SEVERITY_ERROR);
                FacesContext context = FacesContext.getCurrentInstance();
                context.addMessage(null, errMsg);
                e.printStackTrace();
            } catch (IOException e) {
                FacesMessage errMsg = new FacesMessage("Something went wrong");
                errMsg.setSeverity(FacesMessage.SEVERITY_ERROR);
                FacesContext context = FacesContext.getCurrentInstance();
                context.addMessage(null, errMsg);
                e.printStackTrace();
            }
    
    
        }
    
    




  • Now Run your application and see downloaded file in your c drive as path is hard coded in bean


  •  See your downloaded file in c drive


Wednesday 21 November 2012

Shuttle Component in Oracle ADF (Allow Multiple Selection), Get Selected values from Shuttle Component



Hello All

Hope you all are doing well :) 

Shuttle component supports multiple selections at Runtime, when we need to select multiple records at runtime then we can use Shuttle Component.

Now we see how to use shuttle component (af:selectManyShuttle) in Oracle ADF

Shuttle Component in Oracle ADF

Follow these steps-

  • Prepare model for Employees table of HR Schema(Create EO,VO and AM)
  • Now drag Employees ViewObject from DataControl to page and select multiple selection-->ADF Select Many Shuttle-
Drop ViewObject as ADF Select Many Shuttle






  • Now edit binding for this Shuttle Component, choose attribute that you want to show and also base attribute-
    Edit Shuttle binding and select base and display attribute

     
  • Now it will look like this, drag a button to get selected attribute of this shuttle component
    af:selectManyShuttle
     
    Now write code on button's actionEvent to get selected value from Shuttle-


    import oracle.adf.model.BindingContext;
    import oracle.binding.BindingContainer;
    
        /*****Generic Method to get BindingContainer of current page, fragment or region**/
        public BindingContainer getBindingsCont() {
            return BindingContext.getCurrent().getCurrentBindingsEntry();
        }
    

     public void getSelectedValue(ActionEvent actionEvent) {
          //Get Binding Continer of Page
            BindingContainer bc = this.getBindingsCont();
         //Get shuttle binding from pagedef
            JUCtrlListBinding listBindings = (JUCtrlListBinding)bc.get("Employees1");
        //Get Selected Values
            Object str[] = listBindings.getSelectedValues();
        //Iterate over selected values
            for (int i = 0; i < str.length; i++) {
                System.out.println(str[i]);
            }
        }
    

    When you run this it should look like this and your Shuttle is ready
    Get selected value of shuttle component ADF