In a lot of ways, working with JSF 2 is dreamy. It feels even better than RichFaces. I like the way, especially, the basic event/rerendering stuff is implemented. On the negative side, as usual, the documentation is anemic at best and a joke at worst. Which is really hard to excuse, given the fact that this release was in utero for something like half a decade. The only real explanation is that programming now, in the JEE world, is just done with Google. The hipsters think documentation is passé.
The simplest possible example here is an inputText component, and a label that shows how many letters have been typed. This is covered well here. Literally, just add the ajax tag, the event you want to hook (keyup for this one) and the fields to update and you are done.
There are a lot of variants here. You can move the tag up to a containing component and have it apply to the children, for instance.
This is where the picture becomes a bit more murky. Imagine you want to take each keystroke and get its keycode. The scenarios I imagined for this were the following:
- hook the event, but add a listener, then the listener could manipulate the event on the server side
On the first option, the problem is that the event that is sent to the listener is not actually the event you are interested in, with the timestamps, keycode, etc. Instead, it‘s a Behavior event that JSF has that provides no real information.
The second option you can find a lot of super trivial examples and then you can keep returning to the documentation, which isn‘t merely flaccid, turgid, insipid.. it would make a fine entry either in an Obfuscation Jousting Competition, or if someone were willing to award a prize for a page of text the would convince anyone, even a mutli-decade Tibetan monk, that he/she was ADHD (see this here (the whole document is insane, but I linked to the request section, which is really special.. after about the fourth time, I had a beavis flashback: ‘Words, words, words… let‘s go break something..‘)).
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)