Wicket build-in a lot of Ajax fallback components that degrade to a normal request if ajax is not available or Javascript is disabled. Some good examples are AjaxFallbackButton, AjaxFallbackLink… However there are some components that didn’t implement fallback behavior, for instance AjaxLazyLoadPanel. The AjaxLazyLoadPanel will keep display the Wicket’s default image forever if Javascript is disabled.

Is there a function in Wicket to detect the browser’s Javascript is disabled? Yes, it is. Wicket has a build-in mechanism to detect the browser capabilities. However , Wicket turn this function off by default for a reason, i will come back to it later.

Here i will demonstrate how to detect browser’s Javascript is disabled in Wicket

1) Put the following code in Wicket application class. It will tell Wicket to gather extra information from browser’s.

protected void init() {		
		getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
}

2) Put the following code in where we want to assert whether browser’s Javascript is disabled.

WebClientInfo clientInfo = (WebClientInfo)WebRequestCycle.get().getClientInfo();
if(clientInfo.getProperties().isJavaEnabled()){
  //Javascript is enable
}else{
 //Javascript is enable
}

3) Done.

Explanation

When user request a page, Wicket will execute a simple Javascript redirect testing in client browser to assert whether browser’s Javascript is disabled, and save it into user’s session. After executed the redirect testing, Wicket will redirect to the original requested page. The whole process is very fast , but we will see a flash of blank page if our connection is slow. This is why Wicket turn it off by default. The flash of black page really annoying, when we seeing this kind of flash of page, we may assume this site is a phishing site.

Wicket redirect testing page is generic and suitable in all of the cases, however the flash of a blank page really unacceptable , at least for me. Does anyone has any better idea?