There are usecases where, only in phones few components need to be replaced or hided. It may still be displayed in tablets.
The ADF supported and apache supported options currently (Feb 2013) is not able to distinguish between Phone and Tablet. Even though it’s able recognize them as ‘touchable’ client.
Reading the Header information does the trick.
IOS
Mozilla/5.0 (iPhone; CPU iPhone OS 6_0_2 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A551 Safari/8536.25
Mozilla/5.0 (iPad; CPU OS 6_0_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A523 Safari/8536.25
Android
Tablet – Mozilla/5.0 (Linux; U; Android 3.2; en-us; GT-P7510 Build/HTJ85B) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13
Phone – Mozilla/5.0 (Linux; Android 4.2.1; Galaxy Nexus Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19
Code
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); String userAgent = request.getHeader("user-agent"); System.out.println(userAgent);
Other alternatives are but they recognizes both iPhone and iPad as the same (iPhone):
adfFacesContext.getAgent() or org.apache.myfaces.trinidad.context.RequestContext.getCurrentInstance().getAgent();
Javascript code for the same. (Javascript also provides the very same information read from the header. )
function checkPlatform(event) { alert(navigator.platform + ' ------------- ' + navigator.userAgent); AdfCustomEvent.queue(event.getSource(), "handleEnterEvent", {mobilePlatform: navigator.platform}, {userAgent: navigator.userAgent}, true); event.cancel(); }
So now you will be able to switch or hide the component and customize the UI from the server level before serving the client request.
April 22nd, 2013 at 6:27 am
I got this site from my friend who told me on the topic of this web site and now this time I am visiting this site and reading very informative content at this place.
July 10th, 2013 at 10:12 pm
Glad to hear that, you have been benefited.