Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I use method-parameter level validation with JSF 2.2?
    primarykey
    data
    text
    <p>I have created a bean validator that I apply to my bean setter method. Instead of getting a JSF validation error, I get an exception raised. Is there a way to make this work, or I should go with a traditional JSF validator?</p> <pre><code>//Bean Method public void setGuestPrimaryEmail(@ValidEmail String email){ guest.getEmails().get(0).setValue(email); } //Validator interface @Target({ElementType.FIELD,ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = EmailValidator.class) public @interface ValidEmail { String message() default "{invalid}"; Class&lt;? extends Payload&gt;[] payload() default {}; Class&lt;?&gt;[] groups() default {}; } //Validator impl public class EmailValidator implements ConstraintValidator&lt;ValidEmail, String&gt; { private Pattern p; @Override public void initialize(ValidEmail constraintAnnotation) { p = java.util.regex.Pattern .compile("[a-z0-9!#$%&amp;'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&amp;'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"); } @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (DothatUtils.isEmpty(value)) { return true; } boolean invalid = !p.matcher(value).matches(); if (invalid) return false; return true; } } </code></pre> <p>Exception: </p> <pre><code>2013-11-30T20:58:41.747+0000|SEVERE: javax.faces.component.UpdateModelException: javax.el.ELException: /index.xhtml @144,86 value="....": javax.validation.ConstraintViolationException: 1 constraint violation(s) occurred during method validation. </code></pre> <p>Note: I am using GF4 with JSF 2.2.4. If I place my custom annotation on the field, it works as expected.</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.
 

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