Please disable your adblock and script blockers to view this page

Search this blog

Tuesday 10 June 2014

Export ViewObject dataset to XML, Generate customized XML file using ViewObject in Oracle ADF

Hello All,
this post is about exporting a viewObject data to a XML document.
Sometimes we need to generate XML document with the same data in ViewObject, for this ADF provides a facility to directly export data to a XML document using ViewObjectImpl class

See the steps to generate XML for a ViewObject

  • Create a Fusion Web application and model using HR schema (Departments & Employees) table (master detail relation using viewLink)


  • Now to generate XML, i have used writeXML method of ViewObjectImpl class, it produce XML using two parameters



  • from oracle docs-
    writeXML(int depthCount, long options)
    here depthCount - no. of ViewLink levels that should be traversed to produce XML
    options- how many rows you want to export, It can be set any of flags given below
    XMLInterface.XML_OPT_ALL_ROWS
    Includes all rows in the view object's row set in the XML.

    XMLInterface.XML_OPT_LIMIT_RANGE
    Includes only the rows in the current range in the XML.

  • created a method in DepartmentsVOImpl class to export data to XML, added it to client Interface

  •     /**Method to generate XML from ViewObject data
         * @param level
         * @return
         */
        public String writeVoToXml(int level) {
            FileOutputStream out;
            ByteArrayOutputStream opStream = new ByteArrayOutputStream();
            try {
                // Generating XML for All rows and adding it to Output Stream
                ((XMLNode) this.writeXML(level, XMLInterface.XML_OPT_ALL_ROWS)).print(opStream);
                System.out.println(opStream);
                // Creating a XML document in D Drive
                out = new FileOutputStream("D://Departments.xml");
                out.close();
    
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
    
            return opStream.toString();
    
        }
    


  • Now run application module to execute method and see generated XML on console

  • BC4J Tester

    ViewObject XML

  • i have created a simple page with a af:codeEditor to show generated XML , button to generate XML and a spinner to pass depth level of viewLink accessor

  • In case depth level is '0' , it export data only for Departments viewObject

    Change level to '1' , Now it generate XML for Departments --> Employess relation


  • now to how to customize XML ? How to change default tags for attribute names and rows ?
  • To change attribute label (tag in xml)- Suppose i have to change DepartmentName to Name in XML
  • Add attribute level custom property named XML_ELEMENT to a value AnyOtherName to change the XML element name used for that attribute


  • To change Row label (tag in xml)- Suppose i have to change DepartmentsVORow to DepartmentLine in XML
  • Add ViewObject level custom property named XML_ROW_ELEMENT to a value AnyOtherName to change the XML element name used for that Row


  • Now Run and see generated XML -
Cheers :-) Happy Learning

Sunday 8 June 2014

ADF Basics: Using CSS to change appearance of application (Skins and Styles in ADF Faces)

Hello All
This is a basic post about using CSS in ADF applications, how can you change appearance of ADF application using Skins (.css file)
See the steps to create and apply css in your ADF applications
  • Create a Fusion Web Application and create a page
  • Add Some ADF Faces component (input text,button,panel box, panel collection etc)
  • Now to change appearance of default ADF Faces components , create an ADF Skin
  •  Right click on ViewController--->New--->Web Tier--->JSF/Facelets--->ADF Skin 


  • By default ADF Skin name is like skin1,2 etc



  • After creating ADF Faces skin open it and, on left you will see all components as Button, Layouts, Output text and so on. this is ADF Skin Editor


  • Now expand the components that you want to change , change it's color(on active, focus , hover etc) and other properties. See in image below


  • After creating your ADF Skin ,open trinidad-config.xml file in Jdeveloper editor and your will see like this

  • <skin-family>skin1</skin-family>
    
    This means that skin1 is applied on Application

  • now if you another ADF Skin file- skin2 then in trinidad-config.xml, it will be changed to

  • <skin-family>skin2</skin-family>
    

  • ADF automatically choose the most recent skin, so here this is done , now create and configure your ADF Skin and customize appearance of application
  • For more details see Oracle Docs- http://docs.oracle.com/cd/E16764_01/web.1111/b31973/af_skin.htm
Cheers :-) Happy Learning

Wednesday 4 June 2014

ADF Basics : Implementing auto suggest behavior in ADF Faces lov (list of values)


Auto Suggest behavior is best understand by Google Instant, as in google when we type something and it starts showing suggestion instantly.

 This effect can be implemented in ADF using autoSuggestBehaviour
To use the auto-suggest functionality in a declarative way you need to define a model-driven list of values on your model project, which will be the base for the suggestedItems list. Select the Department Name attribute from the Department VO and create a List of Values. here i am using HR schema and predefined table Department to implement this

  • Create a Fusion Web Application
  • Now create EO and VO of Department table.(Business Components)


  • Now create List of values(LOVs)on DepartmentName



  • Create page in ViewController and drag the DepartmentName on page as ADF Lov ChoiceList or Lov Input

  • Now go to Component Palette and select Auto Suggest Behaviour and drop it inside DepartmentName Lov


  • Now select af:autoSuggestBehavior from Page structure and go to PropertyInspector and Open Expression Builder at SuggestedItems and select from bindings #{bindings.DepartmentName.suggestedItems} if you are using different tables and Lov select according to that



  • Now run your page and enjoy autosuggest behavior (ADF Instant) 
Cheers :-) Happy Learning

Read Next Post in Series- Implement contains/endswith behavior in model based autoSuggest Lov (Input list and combo box)