Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to evaluate a FacesComponent property inside a custom component
    primarykey
    data
    text
    <p>Lately, I've been working on a dynamic form project but is stop with a custom component problem. What I have:</p> <p>A faces component for formField:</p> <pre><code>@FacesComponent(value = "formField") public class FormFieldCompositeComponent { private boolean email; } </code></pre> <p>A custom component jsf:</p> <pre><code>&lt;o:validator for="email_text" validatorId="emailValidator" disabled="#{not cc.email}" /&gt; </code></pre> <p>OR</p> <pre><code>&lt;c:if test="#{not cc.email}"&gt; &lt;f:validator for="email_text" validatorId="emailValidator"&gt;&lt;/f:validator&gt; &lt;/c:if&gt; </code></pre> <p>OR</p> <pre><code>&lt;f:validator disabled="#{not cc.email}" for="email_text" validatorId="emailValidator"&gt;&lt;/f:validator&gt; </code></pre> <p>And the validator:</p> <pre><code>@FacesValidator("emailValidator") public class EmailValidator implements Validator { } </code></pre> <p>My problems are:</p> <p>1.) If I use an ordinary f:validator, like the one I use above and then use c:if to enable/disable it, then it will not work. According to some articles I've read it's because f:validator validates on build time, not on render time.</p> <p>2.) If I use o:validator, it works but the problem is every time you hit submit a new line of invalid email error is added to p:messages. Example I clicked submit button 3 times, then I get 3 times the email error.</p> <p>Any idea?</p> <p>More info (anatomy of the project) Example I have a page user with field email, it will include the following custom components:</p> <pre><code>+user.xhtml +formPanel +formField (this is where the validator is defined) +formButtons (the action button) +p:messages is defined </code></pre> <p>user.xhtml</p> <pre><code>&lt;formPanel&gt; &lt;formField field="email" /&gt; &lt;formButtons /&gt; &lt;/formPanel&gt; </code></pre> <p>Command button is like (formButtons):</p> <pre><code>&lt;p:commandButton id="saveButton" rendered="#{cc.attrs.edit}" value="#{messages['action.save']}" action="#{cc.attrs.backingBean.saveOrUpdate()}" icon="ui-icon-check" ajax="#{cc.attrs.ajaxSubmit}"&gt; &lt;c:if test="#{cc.attrs.backingBean.lcid != null}"&gt; &lt;f:param name="cid" value="#{cc.attrs.backingBean.lcid}" /&gt; &lt;/c:if&gt; &lt;/p:commandButton&gt; </code></pre> <p>The p:messages as defined on formPanel:</p> <pre><code>&lt;p:messages id="formMessages" showDetail="true" showSummary="false" redisplay="false"&gt;&lt;/p:messages&gt; </code></pre> <p>Note: <br />1.) What I've noticed is that the validator is called n times, where n is the number of submit or click done.</p> <p>xhtml - <a href="https://github.com/czetsuya/crud-faces/blob/master/crud-faces/src/main/webapp/administration/user/user.xhtml" rel="nofollow">https://github.com/czetsuya/crud-faces/blob/master/crud-faces/src/main/webapp/administration/user/user.xhtml</a></p> <p>the tags - <a href="https://github.com/czetsuya/crud-faces/tree/master/crud-faces/src/main/webapp/resources/tags" rel="nofollow">https://github.com/czetsuya/crud-faces/tree/master/crud-faces/src/main/webapp/resources/tags</a></p> <p>bean component - <a href="https://github.com/czetsuya/crud-faces/tree/master/crud-faces/src/main/java/org/manaty/view/composite" rel="nofollow">https://github.com/czetsuya/crud-faces/tree/master/crud-faces/src/main/java/org/manaty/view/composite</a></p>
    singulars
    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.
 

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