Please disable your adblock and script blockers to view this page

Search this blog

Thursday 29 November 2012

Add Serial No. in Table in ADF, Auto Increment column in ADF table

ADF provides easy way to add a autoincrement column in table to make Serial No. or Sequence Column for table ,thats value autoincrements with no.of rows in table .
You have to follow these steps to do this.

  • Go to tabel properties (property Inspector) and set VarStatus to vs

set varStatus of af:table to vs
  •  Now add a column in table and drop an output text inside this new added column
Add new column to af:table to show serial number for each row
  • Select output text and Go to its property inspector and set value to #{vs.index+1} as it is selected in Expression Builder by going through- 
ExpressionBuilder----->JspObjects--->VS---->index




using varStatus we can access various built in function like index,count etc
  • You have done now run your page and you can see a serial no. column
af:table with serial number column

Tuesday 27 November 2012

GTalk (Google Talk) integration with Java


Hello All

Google Talk is most popular chat client that use your gmail login authentication, and after this tutorial you will be able to create your own Gtalk (if you use swing ), this tutorial shows how to integrate Gtalk with Java.

This example uses Smack API, Smack is an Open Source XMPP (Jabber) client library for instant messaging and presence. A pure Java library, it can be embedded into your applications to create anything from a full XMPP client to simple XMPP integrations such as sending notification messages and presence-enabling devices.



  • Code to integrate Google talk with java
 package chat_Server;
 import org.jivesoftware.smack.ConnectionConfiguration;
 import org.jivesoftware.smack.XMPPConnection;
 import org.jivesoftware.smack.XMPPException;
 import org.jivesoftware.smack.packet.Message;
 public class GtalkChat {
   private static String username = "ashishawasthi000@gmail.com";
   private static String password = "XXXXXXX";
   ConnectionConfiguration connConfig;
   XMPPConnection connection;
   public GtalkChat() throws XMPPException {
     connConfig = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
     connection = new XMPPConnection(connConfig);
     connection.connect();
     connection.login(username, password);
   }
   public void sendMessage(String to, String message) {
     Message msg = new Message(to, Message.Type.chat);
     msg.setBody(message);
     connection.sendPacket(msg);
   }
   public void disconnect() {
     connection.disconnect();
   }
   public static void main(String[] args) throws XMPPException {
     GtalkChat gtalkChat = new GtalkChat();
     gtalkChat.sendMessage("abcdefg@gmail.com",
                "Hii this message is send using Java and Google talk integration.");
     gtalkChat.disconnect();
   }
 }  
  • Change line 7 and line 8 with your username and password respectively



  • Chage line 27 with receiver's email id and type your message
  • Now download SMACK API from its website or click on link below
  • Extract Smack.rar and Add Smack.jar and Smackx.jar to your project
  • Now run the code
  • This code will only send chat , try to receive using your own code

Monday 26 November 2012

Tree Table Component in Oracle ADF(Hierarchical Representation)


Hello All

This post is about ADF Faces Tree Table component (about designing component and get selected value from tree table)

We have a simple sample application that shows how can we use tree table component in Oracle ADF.
Tree Table component represents  Hierarchical view of Master Deatil form of data
Here we take example from HR schema using Employees and Department table
Follow these steps -

  • Create EOs,VOs of Employees and Department table in HR Schema and create association and viewlink between Department To Employees considering Department Id
  • Now go to data control and select Department table and drop it on page as Tree table 

Drop ViewObject as ADF Tree Table
  •  Now we have to edit its bindings, it means you have to select attributes that you want to display in page, and below Department table you should add Employees table using "add" button on top, and select appropriate Iterator in EL picker
Edit tree binding in pageDef
  • Now go to page and select treetable in Structure window of Jdeveloper and Go to its selection listener and copy default value
Override default selection listener
  • And change selection listener set it to bean, click on edit and create new selection listener in Bean




Create custom selection listener in managed bean for af:treeTable
  •  Now go to Selection Listener and Use this code to get Value of selected node in treetable, if you will get value of node you can perform any operation on Tree Table
    public void treeTableSelectionListener(SelectionEvent selectionEvent) {
        String adfSelectionListener = "#{bindings.Department1.treeModel.makeCurrent}";

        FacesContext fctx = FacesContext.getCurrentInstance();
        Application application = fctx.getApplication();
        ELContext elCtx = fctx.getELContext();
        ExpressionFactory exprFactory = application.getExpressionFactory();
        MethodExpression me = null;
        me =
 exprFactory.createMethodExpression(elCtx, adfSelectionListener, Object.class, new Class[] { SelectionEvent.class });
        me.invoke(elCtx, new Object[] { selectionEvent });
       
        RichTreeTable tree = (RichTreeTable)selectionEvent.getSource();
        TreeModel model = (TreeModel)tree.getValue();
        //get selected nodes
        RowKeySet rowKeySet = selectionEvent.getAddedSet();
        Iterator rksIterator = rowKeySet.iterator();
        while (rksIterator.hasNext()) {
            List key = (List)rksIterator.next();
            JUCtrlHierBinding treeBinding = null;
            treeBinding = (JUCtrlHierBinding)((CollectionModel)tree.getValue()).getWrappedData();
            JUCtrlHierNodeBinding nodeBinding = treeBinding.findNodeByKeyPath(key);
            Row rw = nodeBinding.getRow();
            System.out.println("row: " + rw.getAttribute(0)); // You can get any attribute
            System.out.println("View Object name---->" + nodeBinding.getViewObject().getName());

        }
    }
  •  Now run your page and when you will click on any node you will find its value on Console---Cheers Happy Coding!
Sample ADF Application