Tuesday, July 8, 2014

Implementing Auto Suggest in ADF

Took help from http://www.oracle.com/technetwork/developer-tools/jdev/autosuggest-090094.html
Requirement is to auto suggest users while using input field . In this case, there is an inputbox for employee's first name (using the HR schema) where upon entering the character, popup suggests user for the list of employees with the first name starting with the character entered as shown in the figure.


View Layer:
1. Create a jspx page with input box, and add the clientListener attributes to the input box

2. define the af:popup segment in the jspx with selectOneListbox option. Function written on keyup and click of input box would populate the List box in this case

Model Layer:
1. Create the EmployeeVO with View Criteria as:


    and write the java method to populate the Employee List(can be found in the code attached)
2. The backing bean would fetch the List from AppMod using method binding:


Run the jspx and result would be as expected :)


Code can be found @ Auto Suggest


Tuesday, July 1, 2014

How to Upload file in ADF Application

Upload file functionality is implemented using af:inputFile component which provides user with a dialog to select the input file.

File selected can be accessed using vcl of the inputfile which provides the
org.apache.myfaces.trinidad.model.UploadedFile object of the selected file:

using the file object, user can get the attributes like fileName, InputStream etc as:

        UploadedFile file = (UploadedFile) event.getNewValue();
        if (file != null)
        {
          fileName=file.getFilename();
          try {
                inputstream=file.getInputStream();
          } catch (IOException e) {
                e.printStackTrace();
          }

     

User would use this inputstream to upload the file in any given location as(can be written as button action):
        OutputStream outputStream = null;
        try{
            outputStream = new FileOutputStream(new File("C:\\JDeveloper\\mywork\\uploadedFiles\\"+fileName));     //hard coded for now
            int read = 0;
            byte[] bytes = new byte[1024];
            while ((read = inputstream.read(bytes)) != -1) {
                    outputStream.write(bytes, 0, read);
            }
            System.out.println("Done!");
        }catch(Exception e){
            e.printStackTrace();
        }


Attached code can be downloaded from here