Ajax – Conditional update in Primefaces/jsf

ajaxjsfprimefaces

First of all, so that there are no misunderstandings, while this is the same question as PrimeFaces: conditional update on validation I am asking it again, because the answer to that question is not acceptable to me, because while it may have given the original poster a workaround for what they were asking, it doesn't really answer the question, and this workaround doesn't work for me.

So, here's my question: how do I conditionally update a primefaces component based on the results of the submition?

I have a component that must not, under any circumstances be updated UNLESS the validation is successful and backend code was executed successfully. (i.e. if the validation succeeds but there was an SQL exception on the back end, the component still shouldn't be updated).

Why can't I always update it? If the logic doesn't succeed it'll be updated to the same thing it was before the submit button was clicked. Because I can't. It's the captcha component. If you update it via ajax, it disappears, end of story. There was a ticket opened at Primefaces and they closed it as won't fix, because flash compoents aren't supposed to be updated w/ ajax.

So when I submit the form, unless the logic succeeds I need to leave the captcha alone. IF the logic succeeds, I need to make sure the captcha disappears off screen. What's the easiest, cleanest way to do it?

Excuse me if this is a n00b question. I'm really new to Primefaces and JSF.

Best Solution

RequestContext.getCurrentInstance().update("clientId")

Helps for conditional updates.

For recaptcha try

RequestContext.getCurrentInstance().execute("Recaptcha.destroy()");
Related Question