Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking User Agent in Wicket

I am using wicket 1.5 and I am not able to see in the getClientInfo() method

(WebRequest)RequestCycle.get().getRequest()

I saw the other place this code

WebClientInfo clientInfo = (WebClientInfo)WebRequestCycle.get().getClientInfo();

But I am not able to see any WebRequestCycle in Wicket 1.5.

Any ideas how to check the user agent in Wicket 1.5?

like image 729
Wicker User Avatar asked Dec 15 '22 23:12

Wicker User


2 Answers

The easiest way is to use

WebSession.get().getClientInfo().getUserAgent();

On newer Wicket Versions (6 or newer), you should use:

WebClientInfo clientInfo = new WebClientInfo(getRequestCycle());

System.out.println("Client: " + clientInfo.getUserAgent());
System.out.println("Navigator: " + clientInfo.getProperties().getNavigatorAppName() + ", version " + clientInfo.getProperties().getNavigatorAppVersion()  + ", codName: " + clientInfo.getProperties().getNavigatorAppCodeName() + ", plataform: " + clientInfo.getProperties().getNavigatorPlatform() + ", AppCodName: " + clientInfo.getProperties().getNavigatorAppCodeName());
System.out.println("NavigatorUserAgent: " + clientInfo.getProperties().getNavigatorUserAgent());
System.out.println("Tamanho da tela (Width x Height): " + clientInfo.getProperties().getScreenWidth() + " x "  + clientInfo.getProperties().getScreenHeight() );
like image 116
Christoph Leiter Avatar answered Jan 21 '23 16:01

Christoph Leiter


You can also do:

((WebRequest) getRequest()).getHeader("User-Agent")
like image 28
aditsu quit because SE is EVIL Avatar answered Jan 21 '23 17:01

aditsu quit because SE is EVIL