Hi,
I was browsing through ajax implementation (to learn Wicket and ajax), and found out something odd. It seems that it is not possible to have two different AjaxHandlers on the same page. AjaxHandler base class uses static ThreadLocal to prevent including _javascript_ resources more than once. If one would like to use dojo and scriptaculous on the sama page, then only the first one would get its script reference rendered (because they both extend AjaxHandler).
 
 private static final ThreadLocal headContribHolder = new ThreadLocal();
...
 public final void renderHead(HtmlHeaderContainer container)
 {
  if (headContribHolder.get() == null)
  {
   headContribHolder.set(dummy);
   renderHeadInitContribution(container);
  }
  renderHeadContribution(container);
 }
 
I did not test this, though. I'm not fluent with Wicket and ajax, so I found it too time consuming. But I did a simple code fragment that I think proves my case:
 
public class B {
 public static void main(String[] args) {
  System.out.println("start");
  X x = new X();
  Y y = new Y();
  x.start();
  System.out.println(y.isRunning());
  y.end();
  System.out.println(x.isRunning());
 }
}
class BaseTL {
 private static final ThreadLocal flag = new ThreadLocal();
 public void start() {
  flag.set(new Object());
 }
 public void end() {
  flag.set(null);
 }
 
 public boolean isRunning() {
  return flag.get() != null;
 }
 
}
class X extends BaseTL {
}
class Y extends BaseTL {
}
When only x is started y.isRunning() returns also true.
 
Anyway, I think that the framework should provide a way to do "things" only once per request cycle. Using ThreadLocal seems a little bit like a hack to me.
 
/Arto
 

Reply via email to