Reputation: 1272
Lets say i want 3 different *.html
for a WebPage
. F.e. page_small.html
,page_tablet.html
, page_desktop.html
.
How can i detext the screensize
and depending on the screen serve one of my 3 *.html
I found wickets getVariation
but i cant find a good explanation or example. But is this the right way and can someone provide an example?
@Override
public String getVariation() {
WebClientInfo info = (WebClientInfo) Session.get().getClientInfo();
ClientProperties p = info.getProperties();
p.setJavaScriptEnabled(true);
p.setNavigatorJavaEnabled(true);
System.out.println(p.toString());
// Defaults to -1 ????
int width = p.getScreenWidth();
String size;
System.out.println("width = "+width);
if (width < 1024) {
size = "small";
} else if (width < 1280) {
size = "medium";
} else {
size = "large";
}
String s = super.getVariation();
return s == null ? size : s + "_" + size;
}
but width= -1
Upvotes: 2
Views: 149
Reputation: 17513
You need to render at least one page to be able to get the browser info and then use it while rendering the following pages to decide what variation to use.
You can use getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
as @svenmeier suggested or use AjaxClientInfoBehavior
as shown at http://examples7x.wicket.apache.org/ajaxhellobrowser/
But I'd recommend if you use responsive design, i.e. CSS media queries.
Upvotes: 3
Reputation: 5681
Your application does not configure Wicket to gather extended browser information:
protected void init() {
getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
}
Upvotes: 2