Monday, April 30, 2007

DWR's loading message may result in event "lost" in Firefox

When those 'edit' links in manage users/groups/roles are clicked, two events are actually triggered, 1st one is onmousedown event to select table rows (a DWR server call), 2nd one is onclick event to display the dialog (local). Then when we have DWRUtil.useLoadingMessage in page's init() to display loading message. In FireFox, the 2nd onclick event is not captured if the user release the mouse during the message display period. (this is very obvious in QA server, it take a little bit longer to return the DWR call; in our local dev server, it run so fast so almost never happen.) This is because when displaying such loading message, Firebox blocks UI. The release of the mouse is ignored during that block time, thus onclick event isn't triggered. IE doesn't have this problem though.

Note: onmousedown does not garantee that an onclick event will occur on the same target. For example, if you mouse over a link and then press and hold the click button, but then you move off of that link and release the button, the link will not be clicked.

Wednesday, April 25, 2007

Avoid XMLHttpRequest caching


var url = "../index.html?randomKey=" + Math.random() * Date.parse(new Date());

The task is to poll server periodly for availability with a scheduled XMLHttpRequest (using JS's setInterval("heartbeat()", 15*1000); However, in IE the response is cached even though those meta tags such as 'cache-control', 'expired' have been set to no-cache. And I have tried to set these in request header and not helpful either. The ajax calls are still cached and always return status 200 even though server is down and 404 should be returned. The IE caching is based on url, therefore, append a random key will resolve this issue.

Saturday, April 21, 2007

Annotation

Annotations do not directly affect program semantics, but they do affect the way programs are treated by tools and libraries, which can in turn affect the semantics of the running program. Annotations can be read from source files, class files, or reflectively at run time.

They allow you to define metadata in a typesafe way and apply it to a class, method, constructor, field, or parameter.

So what can use use annotations for? Some people envision using annotations for code generation and a replacement for XDoclet. Others, like the J2EE and EJB 3.0 expert groups, see it as a replacement for deployment descriptors. Furthermore, annotations can be used with AOP.

Friday, April 20, 2007

DWR's Method Signature

JS client side


SecPasswordChecker.preLoginCheck (name, password, callback);

Java server side

public String preLoginCheck (String userName, String password, ServletContext servletContext) {..}

The method signatures of DWR method on Javascript side and server side are not equivalent. JS side declare callback whereas server side allows us to add HTTP servlet object (i.e. HttpServletRequest, HttpServletResponse, HttpSession, ServletContext or ServletConfig) declared on your method. DWR will not include it on the generated stub and upon a call of the method it will fill it in automatically.