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?



is there a way to check if flash is enabled using wicket?
JavaScript is not Java!
This method calls in JavaScript navigator.javaEnabled(). It returns if Java is enabled, e.g. if the Java-Plugin for Java-Applets is installed.
cheers,
Witi
This is correct if you mention in general web technology way.
However , This is Wicket, it’s using redirect page function to check the Javascript disable and set the value for “isJavaEnabled” to valuate it.
No, the isJavaEnabled does only refer to available Java functionality. As you already pointed out, JS works without installed JDK/JRE as they are different technologies.
I verified that by using the eclipse built-in-browser: even when isJavaEnabled evaluates to false, all JS functionality (AJAX, et al) works and other wicket JS related variables are successfully evaluated (see below).
To have a true check for JS availability, you might want to check the userproperties for ScreenHeight/Width as they are obtained by using JS. If JS is not available, they are set to -1.
You also don’t have to use “getRequestCycleSettings().setGatherExtendedBrowserInfo(true);”
Regards,
srm
edit: my statement “You also don’t have to use “getRequestCycleSettings().setGatherExtendedBrowserInfo(true);”” is false.
You have to use this also for the screensize values.
Never mind.
i doubt on this statement.
“the isJavaEnabled does only refer to available Java functionality”, as i remembered i did few testing on the Wicket source code.
Thanks for your trick of checking the JavaScript availability
Great post… thanks a lot
[...] How do detect browser javascript or ajax disabled in Wicket? [...]