This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I discovered to my horror that action listenders do not work when I use validation. This is really annoying, as otherwise the code works.
In an included xhtml file I have the following code, and have just started to use PrimeFaces:
In the main xhtml page that includes the above I have added some code for validation:
and in my bean there are a number of action methods, one of which is here.
On selecting a menu item then clicking the command button, the action abunSet0 is fired and data is read in from a file and a list box is populated. This now works much better with PrimeFaces than with straight jsf.
However, if I add a validation component in the main xhtml page, or indeed also in code in the page in the first listing, the action is not fired and the list box is not populated. Why is this and is there an easy way round this? I suspect it has something to do with the order the JSF cycle is executed, and somehow the validation prevents the action from being fired.
I strongly discourage the use of actionListeners. For 95 percent of what you do, an action method is just as capable, and unlike action listeners, can be coded with non-specific POJO code, which makes it easier to test offline and to re-use on other (non-JSF) platforms. I think the whole idea of frivolous use of actionListeners may be a leftover from the days when JSF was still being designed and the mechanisms were much cruder.
Speaking of mechanisms, though, it's a fundamental aspect of the JSF lifecycle that if ANY input value in a post is invalid, the entire operation is rejected. Not only are both action methods and action listeners not invoked, but the backing bean will not be update. The reason for this is that updates of the backing bean are expected to be all-or-none; no bits and pieces of dirty data. And the action code is guaranteed that the bean properties that it works with are not only valid, but have been updated to match the submitted form data before the action code was invoked.
So it's not a bug, it's not even a feature. It's a basic architectural concept.
An IDE is no substitute for an Intelligent Developer.