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 and etc.

Note
However there are some components that didn’t implement the fallback behavior, for instance AjaxLazyLoadPanel, it will keep display the Wicket’s default image forever if JavaScript is disabled.

Solution

Actually, Wicket has a build-in mechanism to detect the if browser is support JavaScript. But, Wicket turn this function off by default for a reason.

1. Gather your browser’s info

In Wicket application, override init() with setGatherExtendedBrowserInfo(true), it tell Wicket to gather extra information from your browser.

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

2. Detect JavaScript

Now, you can detect whether browser is support JavaScript like this :

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

Explanation

When user request a page, Wicket will execute a simple JavaScript redirect testing in client browser to test whether browser’s JavaScript is supported, 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 you will see a flash of blank page. This is why Wicket turn it off by default. The flash of black page is really annoying, when you seeing this kind of flash page, you may assume this site is a phishing site :) , so does your client.

Wicket redirect testing page is generic and suitable in all of the cases, however the flash of a blank page is really unacceptable , at least for me.

Any Java questions or problems? please post at this JavaNullPointer.com forum, see you there ~
[ Read More ] You can find more similar articles at Apache Wicket Tutorials