Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Typically when one uses a custom <code>f:validator</code> tag on a component then this validator will be invoked during lifecycle event phase before values are applied on the server side. When the pending value passes validation it will be applied as the value for the component. If it fails validation then the value will be discarded and typically a validation message will be added.</p> <p>This process won't work in this situation because the determination of whether the value is valid or not for a given input field depends on the pending values for the other input fields, and we have no guarantee for the order in which components will be validated.</p> <p>I typically solve this issue by declaring a PreRender event lifecycle event on the page:</p> <pre><code>&lt;f:event listener="#{manageBean.preRenderValidation}" type="preRenderView" /&gt; </code></pre> <p>Now in my managed bean I can manaully perform such validations after the normal validation and apply request values phase and events phase has been completed.</p> <pre><code>public void preRenderValidation() { // validation logic if (failed) { FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "You have a validation error", null); getCurrentFacesContextInstance().addMessage(null, msg); } // If action redirects to another page or state needs reverted back then this must be done // manually } </code></pre> <p>With the validation error occurring in preRender then particular component events may have already changed certain state or returned navigation actions so these need to be manually reverted in the case of a failed validation. Of course the other way to do this is to maually validate at the beginning of every method.</p>
 

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