Please disable your adblock and script blockers to view this page

Search this blog

Tuesday 17 June 2014

Detect browser & platform information (name,version), server and client IP details in Oracle ADF

Hello All,
This is post is about getting browser details (version, name ) , platform details (Operating System details) ,server and client IP addresses in Oracle ADF Application
sometimes we need these small but important details -

Code to get this information-

        RequestContext requestCtx = RequestContext.getCurrentInstance();
        Agent agent = requestCtx.getAgent();
        String version = agent.getAgentVersion();
        String browser = agent.getAgentName();
        String platform = agent.getPlatformName();
        String platformVersion = agent.getPlatformVersion();
        FacesContext fctx = FacesContext.getCurrentInstance();
        HttpServletRequest request = (HttpServletRequest) fctx.getExternalContext().getRequest();
        StringBuilder detailMsg = new StringBuilder("<html><body><b>Browser Agent and Ip address details</b><br>");
        detailMsg.append("<ul><li><b>Browser-</b>" + browser + "</li><li><b>Version-</b>" + version +
                         "</li><li><b>Plateform-</b>" + platform + "</li>");
        detailMsg.append("<li><b>Plateform Version-</b>" + platformVersion + "</li><li><b>Server IP-</b>" +
                         request.getLocalAddr() + "</li><li><b>Client IP-</b>" + request.getRemoteAddr() +
        FacesMessage errMsg = new FacesMessage(detailMsg.toString());
        fctx.addMessage(null, errMsg);

See the output-
Application running on Mozilla-
Application running on Chrome-
Application running on Internet Explorer-
Cheers :) Happy Learning


  1. Replies
    1. I have shared source code in blog itself , you can use same code in your ADF Application

  2. how can i get current URL ??

    1. You can use this code to get url of current page

      //Get url of current ViewPort
      String viewId = ControllerContext.getInstance().getCurrentViewPort().getViewId();
      String viewUrl = ControllerContext.getInstance().getGlobalViewActivityURL(viewId);

      See more at: Create shortcut of page on a button click in Oracle ADF using JShortcut library (For windows)

  3. i'm using webcenter portal. I want to popup a message for a user who is accessing my portal from specific browser version. How can i do it?

    1. Have you tried code mentioned in blog ?
      You can put a condition to check browswer version or name and then write logic to open popup

    2. I know the coding part but my problem is where to try that code. I'm new to adf and webcenter portal. I have created a webcenter application in my JDeveloper. It has default login page(login.jspx). In this application where do I need to insert my code?
      Where do I need to make changes? Any components or any properties need to be added?? pls guide me.
      My Jdeveloper version is 11g release 1( )
      Build JDEVADF_11.

    3. You can call this code on a button click or on page load for detailed answer post your question on OTN Forum

  4. thanks a lot to share knowledge and experience :)

  5. Can i get Major version for Chrome instead of this WEBKit 537.36?

  6. code not working correct.. in last it shd say chrome 29 not webkit 537