Requirement: I want to get the Browser Details (like the Browser Version, Browser Name), Platform Details (Operating System Details), Server and Client IP addresses in Oracle ADF Application
Solution: For the solution of the above requirement follow the steps as shown below:
Step 1: Create an Oracle ADF Fusion Web Application.
Step 2: Create a demo.jspx page.
Drag and drop an af:button and set text=”Show Details” and actionListener=”#{MyBean.showDetails}”
Thus, the complete code for demo.jspx is shown below:
<?xml version='1.0' encoding='UTF-8'?> <jsp:root xmlns:jsp="" version="2.1" xmlns:f="" xmlns:af=""> <jsp:directive.page contentType="text/html;charset=UTF-8"/> <f:view> <af:document title="demo.jspx" id="d1"> <af:form id="f1"> <af:button text="Show Details" id="b1" actionListener="#{MyBean.showDetails}"/> </af:form> </af:document> </f:view> </jsp:root>
And, the complete code for the MyBean.java class is as below:
package susantotech.com; import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; import javax.faces.event.ActionEvent; import javax.servlet.http.HttpServletRequest; import org.apache.myfaces.trinidad.context.Agent; import org.apache.myfaces.trinidad.context.RequestContext; public class MyBean { public MyBean() { } public void showDetails(ActionEvent actionEvent) { 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 the the 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() + "</li></ul>"); detailMsg.append("</body></html>"); FacesMessage errMsg = new FacesMessage(detailMsg.toString()); errMsg.setSeverity(FacesMessage.SEVERITY_INFO); fctx.addMessage(null, errMsg); } }
Save all and run the application. Thus, the ran application is shown below. Please note this application is running on the Google Chrome Browser.
Click on Show Details button and we will get the below output:
Hence, the solution to our requirement.
If you like the post please comment, share, and do join me on Facebook. Please subscribe to my YouTube Channel for video tutorials.
Thanks & Regards,
Susanto Paul
276 total views, 1 views today