11/20/2013

Primefaces CAPTCHA and Ajax requests

If you are building primefaces GUIs and you are using the <p:captcha> tag, then you might have come across an issue, that when you are sending ajax requests, the CAPTCHA is not updated - even when it fails.
This gets ugly because the CAPTCHA then shows the wrong information to your clients. They can enter the correct CAPTCHA information and form validation will fail.

This is because the primefaces CAPTCHA uses recaptcha that doesn´t support any ajax. The only elegant way to bypass this is to call

Recaptcha.reload();

You can do this from the oncomplete() method of your commandButton that trigger your ajax call.


If you like this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.