How to evaluate a FacesComponent property inside a custom component

czetsuya

Lately, I've been working on a dynamic form project but is stop with a custom component problem. What I have:

A faces component for formField:

@FacesComponent(value = "formField")
public class FormFieldCompositeComponent { 
    private boolean email;
}

A custom component jsf:

<o:validator for="email_text" validatorId="emailValidator" disabled="#{not cc.email}" />

OR

<c:if test="#{not cc.email}">
    <f:validator for="email_text" validatorId="emailValidator"></f:validator>
</c:if>

OR

<f:validator disabled="#{not cc.email}" for="email_text" validatorId="emailValidator"></f:validator>

And the validator:

@FacesValidator("emailValidator")
public class EmailValidator implements Validator { }

My problems are:

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.

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.

Any idea?

More info (anatomy of the project) Example I have a page user with field email, it will include the following custom components:

+user.xhtml
 +formPanel
 +formField (this is where the validator is defined)
  +formButtons (the action button)
  +p:messages is defined

user.xhtml

<formPanel>
  <formField field="email" />
  <formButtons />
</formPanel>

Command button is like (formButtons):

<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}">
    <c:if test="#{cc.attrs.backingBean.lcid != null}">
        <f:param name="cid" value="#{cc.attrs.backingBean.lcid}" />
    </c:if>
</p:commandButton>

The p:messages as defined on formPanel:

<p:messages id="formMessages" showDetail="true" showSummary="false" redisplay="false"></p:messages>

Note:
1.) What I've noticed is that the validator is called n times, where n is the number of submit or click done.

xhtml - https://github.com/czetsuya/crud-faces/blob/master/crud-faces/src/main/webapp/administration/user/user.xhtml

the tags - https://github.com/czetsuya/crud-faces/tree/master/crud-faces/src/main/webapp/resources/tags

bean component - https://github.com/czetsuya/crud-faces/tree/master/crud-faces/src/main/java/org/manaty/view/composite

czetsuya

Seems like there's no chance for the f:validator so I push through o:validator and come up with a workaround. Need to catch if the error is already in the FacesMessages list:

boolean match = false;
for (FacesMessage fm : context.getMessageList()) {
    if (fm.getDetail().equals(message)
            || fm.getSummary().equals(message)) {
        match = true;
        break;
    }
}

if (!match) {
    throw new ValidatorException(facesMessage);
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Evaluate expression inside custom directive

From Dev

How to transform input data inside custom component?

From Dev

How to property call component inside same component using ReactJS?

From Dev

How to set a Component's property value from inside a FileReader event

From Dev

How to access Angular 1.5 component property inside a template

From Dev

How to move a component with a custom property to a separate file in QML

From Dev

'key' property inside component function

From Dev

Add custom property to vuejs component

From Dev

Angular: HostBinding to custom component property

From Dev

How to extend AjaxBehaviorEvent dispatched from @FacesComponent?

From Dev

Netbeans Custom Component with Custom-Class Property

From Dev

How refer and evaluate variable value as object property

From Dev

page.evaluate - how to write to file inside of it?

From Dev

How to evaluate Expression inside Expression in AngularJS

From Dev

How to evaluate a variable inside a variable bash scripting?

From Dev

How to evaluate Expression inside Expression in AngularJS

From Dev

Setting controller property from inside a component

From Dev

Angular 2 declaring dynamic property inside component

From Dev

How to evaluate a spreadsheet formula within a custom function?

From Dev

How to evaluate custom parenthesis expression in C#?

From Java

Delphi Component Custom property not to be saved on the DFM files

From Dev

Programmatically set property expressions on custom SSIS component

From Dev

Programmatically set property expressions on custom SSIS component

From Dev

Using ion-input inside custom component

From Dev

Use custom object inside react component

From Dev

Access permission inside Joomla custom component

From Dev

Use custom object inside react component

From Dev

Angular 2 listen to custom event inside component

From Dev

Custom SVG directive inside button Component

Related Related

  1. 1

    Evaluate expression inside custom directive

  2. 2

    How to transform input data inside custom component?

  3. 3

    How to property call component inside same component using ReactJS?

  4. 4

    How to set a Component's property value from inside a FileReader event

  5. 5

    How to access Angular 1.5 component property inside a template

  6. 6

    How to move a component with a custom property to a separate file in QML

  7. 7

    'key' property inside component function

  8. 8

    Add custom property to vuejs component

  9. 9

    Angular: HostBinding to custom component property

  10. 10

    How to extend AjaxBehaviorEvent dispatched from @FacesComponent?

  11. 11

    Netbeans Custom Component with Custom-Class Property

  12. 12

    How refer and evaluate variable value as object property

  13. 13

    page.evaluate - how to write to file inside of it?

  14. 14

    How to evaluate Expression inside Expression in AngularJS

  15. 15

    How to evaluate a variable inside a variable bash scripting?

  16. 16

    How to evaluate Expression inside Expression in AngularJS

  17. 17

    Setting controller property from inside a component

  18. 18

    Angular 2 declaring dynamic property inside component

  19. 19

    How to evaluate a spreadsheet formula within a custom function?

  20. 20

    How to evaluate custom parenthesis expression in C#?

  21. 21

    Delphi Component Custom property not to be saved on the DFM files

  22. 22

    Programmatically set property expressions on custom SSIS component

  23. 23

    Programmatically set property expressions on custom SSIS component

  24. 24

    Using ion-input inside custom component

  25. 25

    Use custom object inside react component

  26. 26

    Access permission inside Joomla custom component

  27. 27

    Use custom object inside react component

  28. 28

    Angular 2 listen to custom event inside component

  29. 29

    Custom SVG directive inside button Component

HotTag

Archive