Please disable your adblock and script blockers to view this page

Search this blog

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)

Tuesday 27 May 2014

ADF Basics : How to use FacesMessage to show multiline message

FacesMessage component is used to show confirmation, warning or informational message in Oracle ADF .In this tutorial, you will see that how to use FacesMessage component to show Multiline Message. Sometimes we need to show multilines message then how we implement this ?

this is same as FacesMessage implementation, you should know that af:messages support HTML formatting, so we use HTML formatting to show multiline messages
see more about FacesMessage -



http://www.awasthiashish.com/2012/10/show-facesmessage-in-oracle-adf.html
about inline message
http://www.awasthiashish.com/2012/10/show-inline-message-in-oracle-adf.html

Managed bean code to show multiline message in ADF using FacesMessage-


    package multilineMessages.view.bean;
     
    import javax.faces.application.FacesMessage;
    import javax.faces.context.FacesContext;
    import javax.faces.event.ActionEvent;
     
    public class MultilineMessageBean {
        public MultilineMessageBean() {
        }
     
        public void showMessage(ActionEvent actionEvent) {
            StringBuilder message = new StringBuilder("<html><body>");
            message.append("<p><b>Hi This is Frist Line--Oracle ADF Message</b></p>");
            message.append("<p><i>Hi This is Second Line--Oracle ADF Message</i></p>");
            message.append("<p><b>Hi This is Third Line--Oracle ADF Message</b></p>");
            message.append("</body></html>");
            FacesMessage fm = new FacesMessage(message.toString());
            fm.setSeverity(FacesMessage.SEVERITY_INFO);
            FacesContext fctx = FacesContext.getCurrentInstance();
            fctx.addMessage(null, fm);
        }
    }

To use for Error and Warning just change FacesMessage.SEVERITY_INFO to SEVERITY_ERROR or SEVERITY_WARN.
It will look like this
You can change your Message accordingly

 you can also use some html styles (CSS) to change color of text that appears in message body , see the changed code


    public void showMessage(ActionEvent actionEvent) {
        StringBuilder message = new StringBuilder("<html><body>");
        message.append("<p style='color:navy'><b>Hi This is Frist Line--Oracle ADF Message</b></p>");
        message.append("<p style='color:green'><i>Hi This is Second Line--Oracle ADF Message</i></p>");
        message.append("<p style='color:magenta'><b>Hi This is Third Line--Oracle ADF Message</b></p>");
        message.append("<p style='color:red'><b><i>This is Fourth line--Oracle ADF Message</i></b></p>");
        message.append("</body></html>");
        FacesMessage fm = new FacesMessage(message.toString());
        fm.setSeverity(FacesMessage.SEVERITY_INFO);
        FacesContext fctx = FacesContext.getCurrentInstance();
        fctx.addMessage(null, fm);
    }

now see the FacesMessage look like this-
Happy Learning :-) Download Sample App

Friday 23 May 2014

Reading html source of a webpage (url) using Oracle ADF (af:richTextEditor) & Java

This post is about a common question asked in java-

How to read page source of a website ? or how to get html source of an url?

so for that there is a simple piece of code to read html source of a webpage using it's url, and i have added  af:richTextEditor (ADF Faces component for ricj text formatting) to show html form of url source

  • I have a page with one input text to capture url entered by user, a button to fetch html source of that webpage and a af:richTextEditor to show source code in editing mode and in html mode 


  • See how to get webpage source from an url using java and save it to a html file (download a webpage ), Bind inputText and richInputText to managed bean and craete a actionListener on button to get source

  •     // Input text Binding to get URL
        private RichInputText webPageUrlBind;
        // RickInput text Binding to set Source
        private RichTextEditor richTextBind;
        public void setWebPageUrlBind(RichInputText webPageUrlBind) {
            this.webPageUrlBind = webPageUrlBind;
        }
    
        public RichInputText getWebPageUrlBind() {
            return webPageUrlBind;
        }
    
        public void setRichTextBind(RichTextEditor richTextBind) {
            this.richTextBind = richTextBind;
        }
    
        public RichTextEditor getRichTextBind() {
            return richTextBind;
        }
        /**Method to get html source of url (webpage) and set this to rickTextEditor
         * @param actionEvent
         */
        public void getSourceCodeAction(ActionEvent actionEvent) {
            URL url = null;
    
            try {
                if (webPageUrlBind.getValue() != null) {
                    // Define your URL- Get value from input text using binding
                    url = new URL(webPageUrlBind.getValue().toString());
                }
                URLConnection conn = url.openConnection();
    
                // open the stream and put it into BufferedReader
                BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    
                String inputLine;
                String sourceCode = "";
    
                //Save html file (HTML Source Code of given URL)
                String fileName = "D:/web-content.html";
                File file = new File(fileName);
    
                if (!file.exists()) {
                    file.createNewFile();
                }
    
                //use FileWriter to write file
                FileWriter fw = new FileWriter(file.getAbsoluteFile());
                BufferedWriter bw = new BufferedWriter(fw);
                System.out.println("Printing WebPage source on console, Please wait...\n");
                while ((inputLine = br.readLine()) != null) {
                    System.out.println(inputLine);
                    bw.write(inputLine);
                    sourceCode = sourceCode.concat(inputLine);
                }
    
                bw.close();
                br.close();
                richTextBind.setValue(sourceCode);
                AdfFacesContext.getCurrentInstance().addPartialTarget(richTextBind);
                System.out.println("\n\nYour file is save in D drive! Congratulations ");
    
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
    
        }
    




  • now click on button and see , here i am getting source code of this blog http://oracleadf-java.blogspot.in/


  • now switch RichTextMode to see html preview of this source, it is exactly looking like live webpage, it shows one can practice in this ADF Faces's rickTextEditor to learn html tags


  • and see in D drive of your system a file named web-content created , it contains whole source of this webpage
 Cheers - Happy Learning :)

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 :-)