Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As already said Primefaces Captcha component can't be updated by ajax request. But there is a simple solution - update everything but not Captcha component itself.</p> <p>Your XHTML:</p> <pre><code>&lt;h:form id="myForm"&gt; &lt;h:panelGroup id="updateFormAllValuesButNotCaptcha"&gt; Name: &lt;p:inputText id="name" value="#{captchaBean.name}" required="true"/&gt; &lt;br/&gt; Comment: &lt;p:inputTextarea id="comment" value="#{captchaBean.comment}" required="true"/&gt; &lt;br/&gt; &lt;/h:panelGroup&gt; &lt;p:captcha/&gt; &lt;p:commandButton value="click me" update="updateFormAllValuesButNotCaptcha" actionListener="#{captchaBean.someAction}" oncomplete="Recaptcha.reload()" onerror="Recaptcha.reload()"/&gt; &lt;/h:form&gt; &lt;p:messages globalOnly="false" autoUpdate="true"/&gt; </code></pre> <p>Your backing bean:</p> <pre><code>@ManagedBean @ViewScoped public class CaptchaBean implements Serializable { private String name; private String comment; public String getComment() { return comment; } public void setComment(String comment) { this.comment = comment; } public String getName() { return name; } public void setName(String name) { this.name = name; } public void someAction() { FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Done", ""); FacesContext.getCurrentInstance().addMessage(null, msg); } } </code></pre> <p>Note that I am updating <code>updateFormAllValuesButNotCaptcha</code> panel which contains all form input fields but not Captcha itself. It is also important to notice that Captcha can't be reused, so you have to reload it always when ajax request has been completed or ended with error.</p> <p>What you update after commandButton's action succeeded is up to you. You can hide form (do not render it) and show only confirmation message to make sure user won't try to send comment again.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload