Friday, July 6, 2012

jsf commandLink's onclick pitfalls with f:ajax

For jsf commandLink and commandButton, you can attach onclick handler and ajax handler.
Here are several pitfalls you'd like to know

  • First the javascript you attach to commandLink onclick is a piece of code, not a function name. If your function is named as f, the onclick attribute is "f()", not "f".
  • Second, how can you stop the execution flow, in another word, how can you stop the subsequent ajax call from your function "f"? Return false from "f" is not enough. You can link the return code from "f" to onclick like this onclick="return f()".
  • Third, how can you catch the context such as event target and event when onclick is invoked? When onclick is called, two contextal variables are available: this and event. You can pass them to your function like this: onclick="return f(this, event);" or onclick="return f.call(this, event);";

No comments:

Post a Comment