Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label Jdeveloper. Show all posts
Showing posts with label Jdeveloper. Show all posts

Friday 1 August 2014

Exporting viewObject data in text file using af:fileDownloadActionListener in Oracle ADF (12.1.3)

Hello All
This post is about using af:fileDownloadActionListener to generate file on run-time, suppose i have a viewObject and i want to export it's data in CSV or plain text so for this requirement we can generate file at run-time and send it to client UI to download

What is af:fileDownloadActionListener-
as per oracle docs-
The fileDownloadActionListener tag is a declarative way to allow an action source (<commandButton>, <commandLink>, etc.) to programatically send the contents of a file to the user, optionally with a specific content type and filename. Since file downloads must be processed with an ordinary request - not XMLHttp AJAX requests - this tag forces partialSubmit to be false on the parent component, if it supports that attribute.
The fileDownloadActionListener uses the native (browser built-in) filedownload popup, so this popup cannot be configured.

In this post i am using Departments table of HR schema



  • Prepare model part using Departments table and drop it on page as a table and add a button to UI for downloading


  • drop af:fileDownloadActionListener as child of button and set it's property as contentType, method , fileName 


  • Now see code written in download Listener-

  •     /**Method to get BindingsContainer for current page
         * @return
         */
        public BindingContainer getBindingsCont() {
            return BindingContext.getCurrent().getCurrentBindingsEntry();
        }
    
        /**Method to download ViewObject's data in plain text file
         * @param facesContext
         * @param outputStream
         * @throws UnsupportedEncodingException
         * @throws IOException
         */
        public void fileDownloadListener(FacesContext facesContext,
                                         OutputStream outputStream) throws UnsupportedEncodingException, IOException {
            OutputStreamWriter w = new OutputStreamWriter(outputStream, "UTF-8");
            //Get itertaor from bindings
            DCIteratorBinding deptIter = (DCIteratorBinding) getBindingsCont().get("Departments1Iterator");
            //Get ViewObject from Iterator
            ViewObjectImpl vo = (ViewObjectImpl) deptIter.getViewObject();
            ViewAttributeDefImpl[] attrDefs = vo.getViewAttributeDefImpls();
            int count = 0;
            RowSetIterator rsi = vo.createRowSetIterator(null);
            while (rsi.hasNext()) {
                Row nextRow = rsi.next();
                if (nextRow != null) {
                    // Code to iterate over ViewObject's column to get all columns value at runtime
                    for (ViewAttributeDefImpl attrDef : attrDefs) {
                        byte attrKind =
                            attrDefs[count].getAttributeKind(); //checks attribute kind for each element in an array of AttributeDefs
                        if (attrKind != AttributeDef.ATTR_ASSOCIATED_ROW &&
                            attrKind != AttributeDef.ATTR_ASSOCIATED_ROWITERATOR) {
                            String columnName = attrDef.getName();
                            w.write(columnName + " - " + nextRow.getAttribute(columnName) + "  ");
                        }
                    }
                    // Code to create new line text line for new Row
                    w.write(System.getProperty("line.separator"));
                }
            }
            //Flush the writer after wrting file
            w.flush();
        }
    }
    

  • Run this application and click on download button, browser download box appears , open downloaded file and see how your data appears in text file, to export data in a pdf file you have to generate PDF file using some API then you can download it in same way


Cheers:) Happy Learning

Tuesday 29 July 2014

Showing highlighted holiday calendar in af:inputDate date picker (ADF 12.1.3)

Hello All
This post is about showing highlighted days for holidays in af:inputDate and user must not be able to select these dates
here i am using Jdeveloper 12.1.3
you can do this using af:calendar
https://blogs.oracle.com/adf/entry/display_holiday_name_in_af
but i have a requirement to show holidays while user selects date using af:inputDate

so for this requirement first step is easy to do and there is lots of post about disabling specific days in calendar of af:inputDate

Step 1. Disable specific days -
  • you can see there is property in af:inputDate for setting disabled days, this filed takes a value of type List supported by DateListProvider interface




  • for this purpose i have created a bean that implements methods of DateListProvider , in Overridden method i have defined a list that contains dates of holidays that i want to disable in af:inputDate

  • package holiday.view.bean;
    
    import java.util.ArrayList;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.List;
    
    import javax.faces.context.FacesContext;
    
    import org.apache.myfaces.trinidad.model.DateListProvider;
    
    public class HolidayBean implements DateListProvider {
        public HolidayBean() {
        }
    
        @Override
        public List<Date> getDateList(FacesContext facesContext, Calendar calendar, Date date, Date date2) {
            List<java.util.Date> holiDay = new ArrayList();
            holiDay.add(new Date("27-July-2014"));
            holiDay.add(new Date("29-July-2014"));
            holiDay.add(new Date("10-Aug-2014"));
            holiDay.add(new Date("25-Dec-2014"));
            holiDay.add(new Date("01-Jan-2015"));
            holiDay.add(new Date("22-Oct-2014"));
            holiDay.add(new Date("23-Oct-2014"));
            holiDay.add(new Date("24-Oct-2014"));
    
            return holiDay;
            //return Collections.emptyList();
        }
    }
    

  • attached this bean to disabledDays property of af:inputDate


  • now first part is done we can see all holidays as disabled in calendar of af:inputDate

Step 2. Highlight disabled holidays -
  • but it is not easy to find holidays as all are in grey, so i have to highlight all disabled days , so for this requirement , create a skin in viewController project and write this

  • af|chooseDate::regular-day:disabled{
        background-color: red;
        color: ButtonFace;
    }
    

  • af:chooseDate is used because internally af:inputDate opens af:chooseDate as date picker so i have to change property of af:chooseDate, now run your application

Happy Learning :)

Saturday 5 July 2014

Populate af:treeTable programatically using POJO in Oracle ADF (11g & 12c)

Hello All
This post is about creating & populating af:treeTable programmatically in ADF 11g and 12c
treeTable is basically a hierarchical representation of data, using ADF model layer we can create treeTable very easily by defining master-detail relation between viewObjects
see my previous posts on treeTable-
Tree Table Component in Oracle ADF(Hierarchical Representation)
Tree Table Component with declarative presentation in ADF, Access childs without custom selection listener
Expand and Collapse an af:treeTable programmatically in ADF Faces (Oracle ADF)
Refreshing Child Nodes of an af:treeTable / af:tree in Oracle ADF



to populate treeTable programmatically we need to configure data set that fits to tree hierarchy
thanks to Chris Muir's post about programmatic creation of treeTable
http://one-size-doesnt-fit-all.blogspot.in/2007/05/back-to-programming-programmatic-adf.html

there is 4-5 simple steps to do-
  • Create a fusion web application and drop a af:treeTable on page , in treeTable creation wizard select "bind later" 


  • now create managed bean to populate data in treeTable, create a simple List in managed bean of type POJO class (a java class that contains attributes and their accessor  )
  • so in this app i am going to Tv Serial and respective character names in treeTable, for that i have created a class that contains POJO for treeTable

  • import java.util.ArrayList;
    import java.util.List;
    
    
    public class Seasons {
        public Seasons(String name) {
            this.name = name; // To Store Header Values (Storing Seasons Name :))
            characters = new ArrayList<Seasons>(); // To Store Detail Values (Storing Season's Charatcers)
        }
    
        public void setCharacters(List<Seasons> empDet) {
            this.characters = empDet;
        }
    
        public List<Seasons> getCharacters() {
            return characters;
        }
        private String name;
        private List<Seasons> characters;
    
    
        public void setName(String name) {
            this.name = name;
        }
    
        public String getName() {
            return name;
        }
    // This methods directly add characters value in list
        public void addEmp(Seasons employee) {
            characters.add(employee);
        }
    
    }
    

  • In this class the characters list behaves as child of seasons, so in managed bean define a top-level list (that contains both master and detail) and add values

  • See managed Bean Code-
    import java.util.ArrayList;
    import java.util.List;
    
    import org.apache.myfaces.trinidad.model.ChildPropertyTreeModel;
    
    public class ProgrammaticTreeTabBean {
        List<Seasons> seasonList = new ArrayList<Seasons>();
    
        ChildPropertyTreeModel charatcerVal;
    
        public ProgrammaticTreeTabBean() {
            super();
            // Creating tree for Seasons and Characters details
            // Adding Master Values (seasons)
            Seasons season1 = new Seasons("Game of Thrones");
           // Adding Detail Values (Child Node-Characters)
            Seasons character = new Seasons("Tywin Lannister");
            season1.addCharaters(character);
            character = new Seasons("Tyrion Lannister");
            season1.addCharaters(character);
            character = new Seasons("Jaime Lannister");
            season1.addCharaters(character);
            character = new Seasons("Cersie Lannister");
            season1.addCharaters(character);
            character = new Seasons("Ned Stark");
            season1.addCharaters(character);
    
            // Adding Master Values (seasons)
            Seasons season2 = new Seasons("Arrow");
            // Adding Detail Values (Child Node-Characters)
            character = new Seasons("Oliver Queen");
            season2.addCharaters(character);
            character = new Seasons("Moira Queen");
            season2.addCharaters(character);
            character = new Seasons("Laurel Lance");
            season2.addCharaters(character);
            character = new Seasons("Sara Lance");
            season2.addCharaters(character);
    
            // Adding Master Values (seasons)
            Seasons season3 = new Seasons("Vikings");
          // Adding Detail Values (Child Node-Characters)
            character = new Seasons("Ragnar Lothrak");
            season3.addCharaters(character);
    
            // Adding all list to topList
            seasonList.add(season1);
            seasonList.add(season2);
            seasonList.add(season3);
            // Filtering Child Data, ChildPropertyTreeModel creates a TreeModel from a List of beans, see
            // https://myfaces.apache.org/trinidad/trinidad-api/apidocs/org/apache/myfaces/trinidad/model/ChildPropertyTreeModel.html
            charatcerVal = new ChildPropertyTreeModel(seasonList, "characters");
        }
    
        public ChildPropertyTreeModel getCharatcerVal() {
            return charatcerVal;
        }
    }
    

  • Now code part is complete, now configure your treeTable to show data, see XML source of af:treeTable

  • <af:treeTable rowBandingInterval="0" id="tt1"
                                  value="#{pageFlowScope.ProgrammaticTreeTabBean.charatcerVal}" var="node"
                                  rowSelection="single" initiallyExpanded="true">
                        <f:facet name="nodeStamp">
                            <af:column headerText="Node Stamp" id="c1" width="250">
                                <af:outputText value="#{node.name}" id="ot1" inlineStyle="font-weight:bold;"/>
                            </af:column>
                        </f:facet>
                    </af:treeTable>
    

  • Now run your application and check , what you have done ;)
Happy Learning :) Sample ADF Application (12.1.3)

Tuesday 1 July 2014

Using af:deck component to animate content in ADF 12c(12.1.3)

Hello all,
af:deck is new component introduced in ADF 12.1.3, see more detail on Oracle Docs
af:deck-Tag Referance
http://docs.oracle.com/middleware/1213/adf/tag-reference-faces/tagdoc/af_deck.html
ADF Faces Demo Server (deck demo)

As per oracle docs-
The deck component is a container that shows one child component at a time. When changing which child is displayed, the transition can be animated.
This component does not provide any built-in controls for choosing which child is displayed. Instead, you use some other component to control it. For example, you might use an external navigationPane tab bar or perhaps some external commandImageLinks to represent page progress dots. You are not limited to external controls, your deck might be displaying a series of images and you may want to put a link around each image to trigger advancing to the next image. In all of these cases, you will need to use an event handler function to change the displayed child.

So in this post i am going to show - how to use af:deck component with some animation effect?
in this post i am using 6 images to display on 6 different links



  • so designed page like this, inside deck there is 6 images, and there are 6 image links outside deck , each link is associated with managed bean actionListener 

  • <af:panelGroupLayout id="pgl4" layout="horizontal" halign="center">
              <af:link id="l1" icon="#{resource['images:circle-lblue.png']}"
                       actionListener="#{viewScope.DynamicDeckBean.link1Action}" partialSubmit="true"/>
              <af:link id="l2" icon="#{resource['images:circle-lblue.png']}"
                       hoverIcon="#{resource['images:circle-lred.png']}" partialSubmit="true"
                       actionListener="#{viewScope.DynamicDeckBean.link2Action}"/>
              <af:link id="l3" icon="#{resource['images:circle-lblue.png']}"
                       hoverIcon="#{resource['images:circle-lred.png']}" partialSubmit="true"
                       actionListener="#{viewScope.DynamicDeckBean.link3Action}"/>
              <af:link id="l4" icon="#{resource['images:circle-lblue.png']}"
                       hoverIcon="#{resource['images:circle-lred.png']}" partialSubmit="true"
                       actionListener="#{viewScope.DynamicDeckBean.link4Action}"/>
              <af:link id="l5" icon="#{resource['images:circle-lblue.png']}"
                       hoverIcon="#{resource['images:circle-lred.png']}" partialSubmit="true"
                       actionListener="#{viewScope.DynamicDeckBean.link5Action}"/>
              <af:link id="l6" icon="#{resource['images:circle-lblue.png']}"
                       hoverIcon="#{resource['images:circle-lred.png']}" partialSubmit="true"
                       actionListener="#{viewScope.DynamicDeckBean.link6Action}"/>
            </af:panelGroupLayout>
    
  • created binding for deck in managed bean , and added af:transition for back and forward animation for images

  • <af:deck id="d1" displayedChild="i1" binding="#{viewScope.DynamicDeckBean.deckBind}">
              <af:transition triggerType="forwardNavigate" transition="flipLeft"/>
              <af:transition transition="flipRight" triggerType="backNavigate"/>
              <af:image source="#{resource['images:1.jpg']}" shortDesc="Wild Life 1" id="i1"
                        inlineStyle="height:300px;width:500px;"/>
              <af:image source="#{resource['images:2.jpg']}" shortDesc="Wild Life2" id="i2"
                        inlineStyle="height:300px;width:500px;"/>
              <af:image source="#{resource['images:3.jpg']}" shortDesc="Wild Life3" id="i3"
                        inlineStyle="height:300px;width:500px;"/>
              <af:image source="#{resource['images:4.jpg']}" shortDesc="Wild Life4" id="i4"
                        inlineStyle="height:300px;width:500px;"/>
              <af:image source="#{resource['images:5.jpg']}" shortDesc="Wild Life5" id="i5"
                        inlineStyle="height:300px;width:500px;"/>
              <af:image source="#{resource['images:6.jpg']}" shortDesc="Wild Life6" id="i6"
                        inlineStyle="height:300px;width:500px;"/>
            </af:deck>
    

  • Now page looks like this


  • Refer the above links- there is a method to animate deck's child , i have used same method

  • See managed bean code for links and to animate deck child
        // Animate the display of a deck child.
        private void _animateDeckDisplayedChild(UIComponent eventComponent, int newDisplayedChildIndex) {
            // Find the nearest deck ancestor:
            RichDeck deck = null;
            String eventComponentId = eventComponent.getId();
            while (deck == null) {
                if (eventComponent == null) {
                    System.err.println("Unable to locate a deck ancestor from id " + eventComponentId);
                    return;
                } else if (eventComponent instanceof RichDeck) {
                    deck = (RichDeck) eventComponent;
                    break;
                }
                eventComponent = eventComponent.getParent();
            }
            System.out.println("Child is-" + eventComponent.getId());
            String newDisplayedChild = deck.getChildren().get(newDisplayedChildIndex).getId();
    
            // Update the displayedChild:
            System.out.println("Display Child-" + newDisplayedChild);
            deck.setDisplayedChild(newDisplayedChild);
    
            // Add this component as a partial target:
            RequestContext.getCurrentInstance().addPartialTarget(deck);
        }
    

    Code to change image and calling method to animate, here 0,1,2 are index no. of deck's children

    /**Methods to be called on different links to show different images*/
        public void link1Action(ActionEvent actionEvent) {
            UIComponent eventComponent = deckBind;
            _animateDeckDisplayedChild(eventComponent, 0);// 0 for first child of deck
        }
        public void link2Action(ActionEvent actionEvent) {
            UIComponent eventComponent = deckBind;
            _animateDeckDisplayedChild(eventComponent, 1);// 1 for second child of deck
        }
        public void link3Action(ActionEvent actionEvent) {
            UIComponent eventComponent = deckBind;
            _animateDeckDisplayedChild(eventComponent, 2);
        }
        public void link4Action(ActionEvent actionEvent) {
            UIComponent eventComponent = deckBind;
            _animateDeckDisplayedChild(eventComponent, 3);
        }
        public void link5Action(ActionEvent actionEvent) {
            UIComponent eventComponent = deckBind;
            _animateDeckDisplayedChild(eventComponent, 4);
        }
        public void link6Action(ActionEvent actionEvent) {
            UIComponent eventComponent = deckBind;
            _animateDeckDisplayedChild(eventComponent, 5);
        }
    

  • Now run application and click on links :) see how deck works
See live -how af:deck works



So Happy Learning Sample ADF Application

Friday 27 June 2014

Oracle JDeveloper and Oracle ADF 12c (12.1.3.0.0) out (bug fixed and lots of new features introduced)

hello all
ADF & Jdeveloper 12c (12.1.3.0) released with lots of new features and previous (12.1.2.0) bugs are fixed

Bugs Fixed in 12c (12.1.3.0)-

related to af:query, af:tabel filter and scrolling, property inspector, inputlistofvalues, radioGroup, af:message, checkbox, table pagination, context menu, autosuggest in inputlistofValues, shuttle component
Check out complete list of fixed bugs- Bug Fix List



New Features introduced in 12c (12.1.3.0)-

Enjoy some very cool ADF Faces components
  • 30+ chart types, thematic map with zoom and rotation feature
  • new gauge and awaited rating gauge
  • new component af:deck ,like CSS image slider to show multiple child details one by one with slide and fade effect
  • CSS rule for changing button's color and width
  • Export to CSV feature, mouse hover in list view
Check out complete list of features- New In This Release

Happy Learning , Enjoy new Jdev :)

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)

Tuesday 20 May 2014

Blocking row navigation in af:table , synchronize row selection with model in case of validation failure- Oracle ADF

In ADF we often work on editable af:table and when we use af:table to insert ,update or delete data, it is normal to use some validation
but problem is when some validation failure occurs on page (in af:table) ,still we can select another row and it shows as currently selected Row
this is a bit confusing for user as Row Selection of af:table is not synchronized with model or binding layer

See Problem- 
  • I have an editable table on page


  • Added a validation to check negative value in field of LocationId, now navigate to another row


  • See selected focus is on Academic, but problem is when there is validation failure, why it is showing other row as selected ? 



  • If you check in ViewObject , you will find that row with DepartmentName Human Resource is current row

ADF framework provides a property in af:table to control navigation in af:table when there is some error or validation failure- blockRowNavigationOnError
See in oracle docs about this proprty-

Valid Values: always, never, auto


Whether we want to block row navigation in case of validation failure.
This is when you select a row and do some editing inside the table or in a related form, and this editing causes some validation failures. At this time, if you click on a different row in table, we want to block you from moving to the new row.
possible values are: always, never and auto. default value is auto.

  • always means we block the row navigation
  • never means we don't block and let the row navigation happen
  • auto means the framework will make the decision



by default in af:tabel it's value is <auto>


Change it to <always> and now see behavior on page


 now if you try to select another row, it is not get selected and selected focus is on row with validation

Sample ADF Application-Download
Cheers - Happy Learning :-)

Monday 24 March 2014

Iterating ViewObject vertically (get all attributes of ViewObject) programmatically

Hello All,
This post talks about a requirement of getting all attributes (column names) of a viewObject programmatically

  • Create a fusion web application and business component using department table

  • you can see all attributes in  Departments entity object

  • Now to get ViewObject's attributes name , there is a method written in AMImpl class , see it, i have added a facesMessage to show all names on a Message Board



  •     /**Method to get all attributes of a viewObject
         * */
        public void iterateVoVertically() {
            ViewObjectImpl vo = this.getDepartments1();
            ViewAttributeDefImpl[] attrDefs = vo.getViewAttributeDefImpls();
            int count = 0;
            StringBuilder infoMsg =
                new StringBuilder("<html><body><b><p style='color:red'> Attribute of Department ViewObject are-</p></b>");
            infoMsg.append("<ul>");
    
    
            for (ViewAttributeDefImpl attrDef : attrDefs) {
                byte attrKind =
                    attrDefs[count].getAttributeKind(); //checks attribute kind for each element in an array of AttributeDefs
                if (attrKind != AttributeDef.ATTR_ASSOCIATED_ROW && attrKind != AttributeDef.ATTR_ASSOCIATED_ROWITERATOR) {
                    String columnName = attrDef.getName();
                    infoMsg.append("<li> <b>" + attrDef.getName() + "</b></li>");
                    System.out.println("Column Name-" + columnName);
                }
            }
            infoMsg.append("</ul><br>");
            infoMsg.append("</body></html>");
            FacesMessage msg = new FacesMessage(infoMsg.toString());
            msg.setSeverity(FacesMessage.SEVERITY_INFO);
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
    

  • I have called this method through page binding and AM Client on a button of page

  • now on click of button all attributes of Departments ViewObject are shown in FacesMessage, you can use it in your code
 Cheers :-)

Wednesday 5 March 2014

Igonre null values in viewCriteria -Jdeveloper 12c (Not a bug but a change)

Hello All,
In jdev 12c there is some change in viewCriteria design window, there is a checkbox to ignore null values in criteria , in 11g release it was enabled for all values in criteria item

but in 12c it is disabled for all values of ViewCriteria bind variable


there is two different section for creating bind variable in 12c
1. ViewCriteria Bind Variable
2. Query Bind Variable(Required)
So when you create a bind var of string type in query variables.




and use it in viewCriteria , only then this 'ignore null values' checkbox will be enabled


and when you use viewCriteria bind varibles it is disabled  but sometimes you need to change it, so can change it using ViewObject xml source

  • Select ViewCriteria and go to source
  • Now change GenerateIsNullClauseForBindVars="false"  to true

 Cheers :-)