Please disable your adblock and script blockers to view this page

Search this blog

Tuesday 4 June 2013

Fun - Develop Tic Tac Toe game in Oracle ADF/Java

Tic Tac Toe or Naughty Cross is a paper-pencil game for two players and simple in  concept.
I have developed a application on ADF, using JSF page and unbounded adfc-config.xml .
There is nothing to explain, see the sample application at bottom of this post
  • Tic Tac Toe game has 9 square to enter values 0 or X, so for that i have used 9 buttons and images of 0 and X



  • And create a managed bean for all nine buttons, to execute proper conditions for each move
     
  • See managed bean code and conditions for player's move(only Java Code is needed to do this)



  • package ticTacToeADF.view;
    
    import javax.faces.event.ActionEvent;
    
    import oracle.adf.view.rich.component.rich.nav.RichCommandButton;
    
    public class TictactoeBean {
    
        public TictactoeBean() {
        }
        private static String one = "     ";
        private static String two = "     ";
        private static String three = "     ";
        private static String four = "     ";
        private static String five = "     ";
        private static String six = "     ";
        private static String seven = "     ";
        private static String eight = "     ";
        private static String nine = "     ";
        private static boolean check = false;
        private String Result = "";
        private static boolean oneDis = false;
        private static boolean twoDis = false;
        private static boolean threeDis = false;
        private static boolean fourDis = false;
        private static boolean fiveDis = false;
        private static boolean sixDis = false;
        private static boolean sevenDis = false;
        private static boolean eightDis = false;
        private static boolean nineDis = false;
    
    
        public void Button1(ActionEvent actionEvent) {
            if (check == false) {
                this.setOne("X");
    
                check = true;
                this.setOneDis(true);
                System.out.println("Check is--------->" + check);
                if (one.equalsIgnoreCase(two) && two.equalsIgnoreCase(three)) {
                    this.setResult(one + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (one.equalsIgnoreCase(five) && five.equalsIgnoreCase(nine)) {
                    this.setResult(one + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (one.equalsIgnoreCase(four) && four.equalsIgnoreCase(seven)) {
                    this.setResult(one + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
    
    
            } else {
                this.setOne("0");
    
                check = false;
                this.setOneDis(true);
                System.out.println("Check is--------->" + check);
                if (one.equalsIgnoreCase(two) && two.equalsIgnoreCase(three)) {
                    this.setResult(one + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (one.equalsIgnoreCase(five) && five.equalsIgnoreCase(nine)) {
                    this.setResult(one + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (one.equalsIgnoreCase(four) && four.equalsIgnoreCase(seven)) {
                    this.setResult(one + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
    
            }
    
        }
    
        public void Button2(ActionEvent actionEvent) {
            if (check == false) {
                this.setTwo("X");
                check = true;
                this.setTwoDis(true);
                System.out.println("Check is--------->" + check);
                if (two.equalsIgnoreCase(five) && five.equalsIgnoreCase(eight)) {
                    this.setResult(two + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (two.equalsIgnoreCase(one) && one.equalsIgnoreCase(three)) {
                    this.setResult(two + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
            } else {
                this.setTwo("0");
                check = false;
                this.setTwoDis(true);
                System.out.println("Check is--------->" + check);
                if (two.equalsIgnoreCase(five) && five.equalsIgnoreCase(eight)) {
                    this.setResult(two + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (two.equalsIgnoreCase(one) && one.equalsIgnoreCase(three)) {
                    this.setResult(two + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
            }
        }
    
        public void Button3(ActionEvent actionEvent) {
            if (check == false) {
                this.setThree("X");
                check = true;
                this.setThreeDis(true);
                System.out.println("Check is--------->" + check);
    
                if (three.equalsIgnoreCase(six) && six.equalsIgnoreCase(nine)) {
                    this.setResult(three + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (three.equalsIgnoreCase(five) && five.equalsIgnoreCase(seven)) {
                    this.setResult(three + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (three.equalsIgnoreCase(one) && one.equalsIgnoreCase(two)) {
                    this.setResult(three + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
    
            } else {
                this.setThree("0");
                check = false;
                this.setThreeDis(true);
                System.out.println("Check is--------->" + check);
    
                if (three.equalsIgnoreCase(six) && six.equalsIgnoreCase(nine)) {
                    this.setResult(three + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (three.equalsIgnoreCase(five) && five.equalsIgnoreCase(seven)) {
                    this.setResult(three + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (three.equalsIgnoreCase(one) && one.equalsIgnoreCase(two)) {
                    this.setResult(three + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
            }
        }
    
        public void Button4(ActionEvent actionEvent) {
            if (check == false) {
                this.setFour("X");
                check = true;
                this.setFourDis(true);
                System.out.println("Check is--------->" + check);
    
                if (four.equalsIgnoreCase(one) && one.equalsIgnoreCase(seven)) {
                    this.setResult(four + " wins");
                    finishgame();
                    System.out.println("four wins");
                } else if (four.equalsIgnoreCase(five) && five.equalsIgnoreCase(six)) {
                    this.setResult(four + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
    
            } else {
                this.setFour("0");
                check = false;
                this.setFourDis(true);
                System.out.println("Check is--------->" + check);
    
                if (four.equalsIgnoreCase(one) && one.equalsIgnoreCase(seven)) {
                    this.setResult(four + " wins");
                    finishgame();
                    System.out.println("four wins");
                } else if (four.equalsIgnoreCase(five) && five.equalsIgnoreCase(six)) {
                    this.setResult(four + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
            }
        }
    
        public void Button5(ActionEvent actionEvent) {
            if (check == false) {
                this.setFive("X");
                check = true;
                this.setFiveDis(true);
                System.out.println("Check is--------->" + check);
    
                if (one.equalsIgnoreCase(five) && five.equalsIgnoreCase(nine)) {
                    this.setResult(five + " wins");
                    finishgame();
                    System.out.println("One wins");
    
                } else if (two.equalsIgnoreCase(five) && five.equalsIgnoreCase(eight)) {
                    this.setResult(five + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
    
                else if (four.equalsIgnoreCase(five) && five.equalsIgnoreCase(six)) {
                    this.setResult(five + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (five.equalsIgnoreCase(three) && three.equalsIgnoreCase(seven)) {
                    this.setResult(five + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
            } else {
                this.setFive("0");
                check = false;
                this.setFiveDis(true);
                System.out.println("Check is--------->" + check);
    
                if (one.equalsIgnoreCase(five) && five.equalsIgnoreCase(nine)) {
                    this.setResult(five + " wins");
                    finishgame();
                    System.out.println("One wins");
    
                } else if (two.equalsIgnoreCase(five) && five.equalsIgnoreCase(eight)) {
                    this.setResult(five + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
    
                else if (four.equalsIgnoreCase(five) && five.equalsIgnoreCase(six)) {
                    this.setResult(five + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (five.equalsIgnoreCase(three) && three.equalsIgnoreCase(seven)) {
                    this.setResult(five + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
    
            }
        }
    
        public void Button6(ActionEvent actionEvent) {
            if (check == false) {
                this.setSix("X");
                check = true;
                this.setSixDis(true);
                System.out.println("Check is--------->" + check);
    
                if (four.equalsIgnoreCase(five) && five.equalsIgnoreCase(six)) {
                    this.setResult(six + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (three.equalsIgnoreCase(six) && six.equalsIgnoreCase(nine)) {
                    this.setResult(six + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
            } else {
                this.setSix("0");
                check = false;
                this.setSixDis(true);
                System.out.println("Check is--------->" + check);
    
                if (four.equalsIgnoreCase(five) && five.equalsIgnoreCase(six)) {
                    this.setResult(six + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (three.equalsIgnoreCase(six) && six.equalsIgnoreCase(nine)) {
                    this.setResult(six + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
            }
        }
    
        public void Button7(ActionEvent actionEvent) {
            if (check == false) {
                this.setSeven("X");
                check = true;
                this.setSevenDis(true);
                System.out.println("Check is--------->" + check);
    
                if (four.equalsIgnoreCase(one) && one.equalsIgnoreCase(seven)) {
                    this.setResult(four + " wins");
                    finishgame();
                    System.out.println("four wins");
                } else if (five.equalsIgnoreCase(three) && three.equalsIgnoreCase(seven)) {
                    this.setResult(seven + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (seven.equalsIgnoreCase(eight) && eight.equalsIgnoreCase(nine)) {
                    this.setResult(seven + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
            } else {
                this.setSeven("0");
                check = false;
                this.setSevenDis(true);
                System.out.println("Check is--------->" + check);
                if (four.equalsIgnoreCase(one) && one.equalsIgnoreCase(seven)) {
                    this.setResult(four + " wins");
                    finishgame();
                    System.out.println("four wins");
                } else if (five.equalsIgnoreCase(three) && three.equalsIgnoreCase(seven)) {
                    this.setResult(seven + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (seven.equalsIgnoreCase(eight) && eight.equalsIgnoreCase(nine)) {
                    this.setResult(seven + " wins");
                    finishgame();
                    System.out.println("One wins");
                }
            }
        }
    
        public void Button8(ActionEvent actionEvent) {
            if (check == false) {
                this.setEight("X");
                check = true;
                this.setEightDis(true);
                System.out.println("Check is--------->" + check);
                if (eight.equalsIgnoreCase(two) && two.equalsIgnoreCase(five)) {
                    this.setResult(eight + " wins");
                    finishgame();
                    System.out.println("four wins");
                } else if (eight.equalsIgnoreCase(seven) && seven.equalsIgnoreCase(nine)) {
                    this.setResult(eight + " wins");
                    finishgame();
                    System.out.println("One wins");
    
                }
            } else {
                this.setEight("0");
                check = false;
                this.setEightDis(true);
                System.out.println("Check is--------->" + check);
                if (eight.equalsIgnoreCase(two) && two.equalsIgnoreCase(five)) {
                    this.setResult(eight + " wins");
                    finishgame();
                    System.out.println("four wins");
                } else if (eight.equalsIgnoreCase(seven) && seven.equalsIgnoreCase(nine)) {
                    this.setResult(eight + " wins");
                    finishgame();
                    System.out.println("One wins");
    
                }
            }
        }
    
        public void Button9(ActionEvent actionEvent) {
            if (check == false) {
                this.setNine("X");
                check = true;
                this.setNineDis(true);
                System.out.println("Check is--------->" + check);
                if (nine.equalsIgnoreCase(one) && one.equalsIgnoreCase(five)) {
                    this.setResult(nine + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (three.equalsIgnoreCase(six) && six.equalsIgnoreCase(nine)) {
                    this.setResult(six + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (eight.equalsIgnoreCase(seven) && seven.equalsIgnoreCase(nine)) {
                    this.setResult(eight + " wins");
                    finishgame();
                    System.out.println("One wins");
    
                }
            } else {
                this.setNine("0");
                check = false;
                this.setNineDis(true);
                System.out.println("Check is--------->" + check);
    
                if (nine.equalsIgnoreCase(one) && one.equalsIgnoreCase(five)) {
                    this.setResult(nine + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (three.equalsIgnoreCase(six) && six.equalsIgnoreCase(nine)) {
                    this.setResult(six + " wins");
                    finishgame();
                    System.out.println("One wins");
                } else if (eight.equalsIgnoreCase(seven) && seven.equalsIgnoreCase(nine)) {
                    this.setResult(eight + " wins");
                    finishgame();
                    System.out.println("One wins");
    
                }
            }
        }
    
        public void setOne(String one) {
            this.one = one;
        }
    
        public String getOne() {
            return one;
        }
    
        public void setTwo(String two) {
            this.two = two;
        }
    
        public String getTwo() {
            return two;
        }
    
        public void setThree(String three) {
            this.three = three;
        }
    
        public String getThree() {
            return three;
        }
    
        public void setFour(String four) {
            this.four = four;
        }
    
        public String getFour() {
            return four;
        }
    
        public void setFive(String five) {
            this.five = five;
        }
    
        public String getFive() {
            return five;
        }
    
        public void setSix(String six) {
            this.six = six;
        }
    
        public String getSix() {
            return six;
        }
    
        public void setSeven(String seven) {
            this.seven = seven;
        }
    
        public String getSeven() {
            return seven;
        }
    
        public void setEight(String eight) {
            this.eight = eight;
        }
    
        public String getEight() {
            return eight;
        }
    
        public void setNine(String nine) {
            this.nine = nine;
        }
    
        public String getNine() {
            return nine;
        }
    
        public void setResult(String Result) {
            this.Result = Result;
        }
    
        public String getResult() {
            return Result;
        }
    
        public void ResetButton(ActionEvent actionEvent) {
            this.one = "     ";
            this.two = "     ";
            this.three = "     ";
            this.four = "     ";
            this.five = "     ";
            this.six = "     ";
            this.seven = "     ";
            this.eight = "     ";
            this.nine = "     ";
            this.check = false;
            this.oneDis = false;
            this.twoDis = false;
            this.threeDis = false;
            this.fourDis = false;
            this.fiveDis = false;
            this.sixDis = false;
            this.sevenDis = false;
            this.eightDis = false;
            this.nineDis = false;
    
        }
    
        public void finishgame() {
            this.oneDis = true;
            this.twoDis = true;
            this.threeDis = true;
            this.fourDis = true;
            this.fiveDis = true;
            this.sixDis = true;
            this.sevenDis = true;
            this.eightDis = true;
            this.nineDis = true;
        }
    
        public void setOneDis(boolean oneDis) {
            this.oneDis = oneDis;
        }
    
        public boolean isOneDis() {
            return oneDis;
        }
    
        public void setTwoDis(boolean twoDis) {
            this.twoDis = twoDis;
        }
    
        public boolean isTwoDis() {
            return twoDis;
        }
    
        public void setThreeDis(boolean threeDis) {
            this.threeDis = threeDis;
        }
    
        public boolean isThreeDis() {
            return threeDis;
        }
    
        public void setFourDis(boolean fourDis) {
            this.fourDis = fourDis;
        }
    
        public boolean isFourDis() {
            return fourDis;
        }
    
        public void setFiveDis(boolean fiveDis) {
            this.fiveDis = fiveDis;
        }
    
        public boolean isFiveDis() {
            return fiveDis;
        }
    
        public void setSixDis(boolean sixDis) {
            this.sixDis = sixDis;
        }
    
        public boolean isSixDis() {
            return sixDis;
        }
    
        public void setSevenDis(boolean sevenDis) {
            this.sevenDis = sevenDis;
        }
    
        public boolean isSevenDis() {
            return sevenDis;
        }
    
        public void setEightDis(boolean eightDis) {
            this.eightDis = eightDis;
        }
    
        public boolean isEightDis() {
            return eightDis;
        }
    
        public void setNineDis(boolean nineDis) {
            this.nineDis = nineDis;
        }
    
        public boolean isNineDis() {
            return nineDis;
        }
    
    
    }
    

  • Download and Run this sample application-Sample ADF Application 

Saturday 1 June 2013

Using JQuery in Oracle ADF

JQuery is advance javascript library to support client side scripting of HTML, it is free and Opensource software licensed under MIT.
Jquery is designed to make it easier to create animations, enhance look feel of component, smooth navigation.
Read about Jquery- http://jquery.com/ , https://jquery.org/
here i am showing you, how to add Jquery in oracle ADF application.

  • First add Jquery library to your fusion web application, download library file Download
  • Add this file to javascript resources, see image
  • Now create a javascript(Jquery) file to change color of af:inputText, here is javascript code is given




  • function changeColor() {
        if ($("input[name=it1]").val() != null) {
           if (($("input[name=it1]").val().length > 0) && ($("input[name=it1]").val().length < 3)) {
                $("input[name=it1]").css("color", "magenta");
            }
          else if (($("input[name=it1]").val().length > 3) && ($("input[name=it1]").val().length < 6)) {
                $("input[name=it1]").css("color", "red");
            }
            else if (($("input[name=it1]").val().length >= 6) && ($("input[name=it1]").val().length < 9)) {
                $("input[name=it1]").css("color", "yellow");
            }
             else if (($("input[name=it1]").val().length >= 9) && ($("input[name=it1]").val().length < 12)) {
                $("input[name=it1]").css("color", "maroon");
            }
             else if (($("input[name=it1]").val().length >= 12) && ($("input[name=it1]").val().length < 15)) {
                $("input[name=it1]").css("color", "teal");
            }
             else if (($("input[name=it1]").val().length >= 15) && ($("input[name=it1]").val().length < 18)) {
                $("input[name=it1]").css("color", "blue");
            }
            else {
                $("input[name=it1]").css("color", "green");
            }
        }
    }
    

  • Now create a jspx page , and call this JS file as a resource in jspx page, and also add Jquery Lib to jspx page as Resource

  • Now add a input text in page, and call javascript resource using af:clientListener

  • See the code of jspx page-

  • <?xml version='1.0' encoding='UTF-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
              xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
        <jsp:directive.page contentType="text/html;charset=UTF-8"/>
        <f:view>
            <af:document title="JqueryADF.jspx" id="d1">
             <af:resource type="javascript" source="/javascript/libs/jquery-1.4.4.js"/>
             <af:resource type="javascript" source="/resources/js/inputText.js"/>
                <af:form id="f1">
                <af:inputText label="Chck JQ" id="it1" contentStyle="font-weight:bold;">
                            <af:clientListener type="keyDown" method="changeColor"/>
                        </af:inputText>
                
                </af:form>
            </af:document>
        </f:view>
    </jsp:root>
    

  • Now Run this application and enter value in input text field and see how color is changing with length




  • You can use this , with your password field, for any kind of alert, to make 'Find and Enter' games
  • One more thing , it is difficult to use Jquery with pagefragments because in page fragments component id's are like :t1:cb1, r1:t1:it2. and jquery does not support ':' so you can easily use this with .jspx page
  • Sample ADF application -Download

Thursday 30 May 2013

Add Custom Flash Chat in Oracle ADF Application

In this tutorial i am going to show that how can you add a custom flash chat in your ADF application, and use it to chat with friends.
this is very much simple, as no code required to do this.
  • Go to http://www.everywherechat.com/ , this site provides free custom flash chat rooms, get html code of your custom chat from here
  • Create an html page using that code




  • <html>
    <body>
    <!-- Begin Everywherechat Room Code -->
        
          <br />
         <script src="http://www.everywherechat.com/e.php?defaultRoom=Lobby&roomList=true&fontSize=12&width=600&height=500&theme=night"></script> 
    
    <!-- End Everywherechat Room Code --> 
    </body>
    </html>
    

  • Now create a Fusion Web Application and create a page in it, call this HTML page in an inlineFrame (af:inlineFrame)

  • <?xml version='1.0' encoding='UTF-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
      <af:panelGroupLayout id="pgl1">
        <af:inlineFrame id="if1" source="/chat.html" inlineStyle="height:700px;width:700px;"/>
      </af:panelGroupLayout>
    </jsp:root>
    

  • Now Run your application and see your flash chat room is ready - Happy Coding

    Download Sample Application-Sample ADF Application

Tuesday 21 May 2013

Generate Barcode Image in Oracle ADF using OnBarcode API

In this tutorial we will learn how to generate Barcode Image for any Number(Barcode) in ADF using OnBarcode API, this API provides barcode SDK(Software Development Kit) to generate Barcode. This is paid.
You can get it from http://www.onbarcode.com/  , click on Download to get barcode SDK.
  • Now create a fusion web application and add barcode.jar to project libraries, you will get this JAR , when you download SDK
  • Good thing about this API is that it is very simple to use, not much code required to generate a simple barcode image
  • You can generate multiple type of Barcode as Code 39, Code 128, EAN-8, EAN-13, UPC-A, UPC-E
  • Suppose i have to generate a Code128 type of Barcode for any barcode number, so for this write this simple code and you are done




  • Code128 barcode = new Code128();
    
    barcode.setData("122322311");
    barcode.drawBarcode();  
     
  • Download sample application that integrates this API with Oracle ADF Download Sample ADF Application 
  • Unzip and Run this application

     
  • I have used a servlet in order to show image on page fragment

Monday 20 May 2013

Set and Get Value from Taskflow parameter (pageFlowScope variable) from Managed Bean- ADF

Hello All

This post is about getting and setting value in taskFlow parameter using Java Code so for that we have created a application with bounded taskFlow

Let's see how to do this -

We have bounded taskflow having Input Parameter defined in it named GLBL_PARAM_TEST

Bounded Taskflow Input Parameters

and we have to set its value from managed bean.
this is very simple -see how to do that
  • Get pageFlowScope Map and put parameter 's value in it

  •         Map paramMap = RequestContext.getCurrentInstance().getPageFlowScope();
            paramMap.put("GLBL_PARAM_TEST", "Ashish"); 

  • And get Value from taskFlow parameter in managed bean



  •     public String resolvEl(String data){
                   FacesContext fc = FacesContext.getCurrentInstance();
                   Application app = fc.getApplication();
                   ExpressionFactory elFactory = app.getExpressionFactory();
                   ELContext elContext = fc.getELContext();
                   ValueExpression valueExp = elFactory.createValueExpression(elContext, data, Object.class);
                   String Message=valueExp.getValue(elContext).toString();
                   return Message;
                 }
    
    
    String param=resolvEl("#{pageFlowScope.GLBL_PARAM_TEST}");
    

Wednesday 15 May 2013

Beauty of ADF- Taskflow, Difference b/w Facelets and JSP XML fragments in bounded taskflow

Oracle ADF framework support modular architecture for enterprize application development. Multiple small module can be bound together to form a large module .
The greatest advantage of ADF controller over core JSF navigation model is that it splits a single bulky module to multiple reusable and interconnected modules known as Taskflows.

i am not going deeper in Taskflows as every ADF developer know about it ,so the important part is page fragment.
  • When  we create taskflow as bounded taskflow , and check it to create fragment in taskflow.
  • Now when we create pagefragment in bounded taskflow, there is 2 option for creating fragment




Create fragment as Facelets
Create fragment as JSP XML 

Page Fragment Type - Facelets or JSPX

Facelets- is default and official view handler for JSF pages, priviously JSP was used to view JSF pages but it didn't support all component so Facelets comes in picture under APACHE open source license. It supprts all UI component used by JSF (Java Server Faces).
Facelets was developed by Jacob Hookom in 2005.
If you create Facelets fragment in bounded taskflow, then taskflow must be dropped in a JSF page (parent page) not in .jspx (JSP XML ) page.
if you try to drop it into JSP XML page-


JSP XML- jspx is XML variant of JSP(Java Server Pages) to support XML document . JSP XML fragments are used in ADF inorder to support XML document and more powerful page validation techniques.
If you create jsp xml fragments in bounded taskflow, then taskflow must be dropped in a JSP XML(.jspx) page(parent page) not in JSF page.

Tuesday 14 May 2013

Using Contextual Event in Oracle ADF (Region Communication)

Contextual event ,in simple terms is a way to communicate between taskflows.
Sometimes we have taskflow open in a region and have to get some values from that taskflow .
This scenario can be achieved by contextual event.

 
Contextual Event have two parts-
  1. Publisher Event (Producer)- As button or any component that can raise event 
  2. Handler Event (Customer)- that listens and process event published by producer
This tutorial is based on example developed on default HR schema of Oracle DB 11g
I have created two application and called first one in secod application as region.
  • Create first application using Department table of HR schema and drag Department Name on page fragment, now create publisher event (follow steps) for Department Name .
  • Select Department Name field in structure window and go to property Inspector select ContextualEvent
    click on green add icon and select event type and name for publisher event

  • Select field value from Iterator Binding
  • here you are done with publisher event or producer create a jar of this application in order to use it in second application.
  • Now start Second Application that will handle and process this event, create a page and put an output text and set its value from managed bean


  • Now create a event handler class to process published event and to make it available to page binding level , we have to create DataControl for this class.





  • Right click on event class and Click on CreateDataControl.
  • Now add this method binding to page so that it can be accessible from page binding
  • Now drag and drop taskflow from jar library on page as region by this published event will also be available to page
  • Now go to page binding and goto ContextualEvents tab ,click on subscribers tab and click on add icon this will open a popup window ,click on search button , it will show available publisher event, now select event and goto handler search option and select function that you have previously added in page binding
  • Give consumer parameter name same as event handler function

Now Run your Application - Download ADF Sample Application

Monday 13 May 2013

Phone Number custom validation using Regular Expression in ADF and Java




Regular Expression (REGEX) is the best method to validate phone number. emailId, name in Java.
Here I have written this validation code for phone number using Regular Expression and Java code to use this in an Oracle ADF Application.





public void phoneNoValidator(FacesContext facesContext, UIComponent uIComponent, Object object) {
        String msg2 = "";
        if (object != null) {
            String phnNo = object.toString();
            int openB = 0;
            int closeB = 0;
            boolean closeFg = false;
            char[] xx = phnNo.toCharArray();
            for (char c : xx) {
                if (c == '(') {
                    openB = openB + 1;
                } else if (c == ')') {
                    closeB = closeB + 1;
                }

                if (closeB > openB) {
                    closeFg = true; //closed brackets will not be more than open brackets at any given time.
                }
            }
            //if openB=0 then no. of closing and opening brackets equal || opening bracket must always come before closing brackets
            //closing brackets must not come before first occurrence of openning bracket
            if (openB != closeB || closeFg == true || (phnNo.lastIndexOf("(") > phnNo.lastIndexOf(")")) ||
                (phnNo.indexOf(")") < phnNo.indexOf("("))) {
                msg2 = "Brackets not closed properly.";
                FacesMessage message2 = new FacesMessage(msg2);
                message2.setSeverity(FacesMessage.SEVERITY_ERROR);
                throw new ValidatorException(message2);
            }
            if (phnNo.contains("()")) {
                msg2 = "Empty Brackets are not allowed.";
                FacesMessage message2 = new FacesMessage(msg2);
                message2.setSeverity(FacesMessage.SEVERITY_ERROR);
                throw new ValidatorException(message2);
            }
            if (phnNo.contains("(.") || phnNo.contains("(-") || phnNo.contains("-)")) {
                msg2 = "Invalid Phone Number.Check content inside brackets.";
                FacesMessage message2 = new FacesMessage(msg2);
                message2.setSeverity(FacesMessage.SEVERITY_ERROR);
                throw new ValidatorException(message2);
            }

            openB = 0;
            closeB = 0;
            closeFg = false;
            //check for valid language name.Allowed- brackets,dots,hyphen

            String expression = "([0-9\\-\\+\\(\\)]+)";
            CharSequence inputStr = phnNo;
            Pattern pattern = Pattern.compile(expression);
            Matcher matcher = pattern.matcher(inputStr);
            String error = "Invalid Phone Number";
            System.out.println("Index of plus is--->" + phnNo.lastIndexOf("+"));
            System.out.println("Bracket index--->" + phnNo.charAt(0));

            if (matcher.matches()) {
                if (phnNo.contains("++") || phnNo.contains("--")) {
                    throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, error,
                                                                  "Can not contain two hyphen(--) or plus(++)"));
                } else if (phnNo.lastIndexOf("+") > 1) {
                    throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, error,
                                                                  "Plus sign should be in proper place"));
                } else if (phnNo.lastIndexOf("+") == 1 && phnNo.charAt(0) != '(') {
                    throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, error,
                                                                  "Plus sign should be in proper place"));
                } else if (phnNo.startsWith(" ") || phnNo.endsWith(" ")) {
                    throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, error,
                                                                  "Space Not allowed at start and end"));
                }

            } else {
                throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, error,
                                                              "Only numeric character,+,() and - allowed"));
            }

        }
    }


Cheers:) Happy Learning

Sunday 5 May 2013

Social Media Integration with Oracle ADF- Add Facebook like,share ,twitter ,LinkedIn button to your ADF page

This tutorial is dedicated to Social Media, beacuse of its importance in our daily life.
In this tutorial you will see that how can we use social media plugins in our ADF Application as Facebook like button,twitter and LinkedIn share button.

Read In detail