jsf 2.2 - JSF 2.2 Controller Validation - Doesn't seem to fire -


hi have contrived controller:

@model @fieldmatch(first = "username", second = "usernameagain", message = "the email fields must match") public class hellocontroller implements serializable {      private static final long serialversionuid = -8187960089787583270l;     private string username;     private string usernameagain;      private static final logger log = loggerfactory.getlogger(hellocontroller.class.getname());      // final static validatorfactory factory = validation.builddefaultvalidatorfactory();     // private static validator validator = factory.getvalidator();      public string login() {          // final set<constraintviolation<hellocontroller>> violations = validator.validate(this);         // log.info(violations.tostring());         final boolean valid = isvalid();         log.info("{valid: " + valid + "},{username: " + username + "}, {usernameagain: " + usernameagain + "}");          return null;      }      @asserttrue(message = "no valid")     private boolean isvalid() {        return username.equals(usernameagain);     } 

in looking proper way validate fields equal, started researching jsf validation, led me hibernate's implementation. came across gem: cross field validation hibernate validator (jsr 303)

so if put @notnull/@size/etc... on username , usernameagain validation works.

however when "login()" neither fieldmatch or isvalid() (see above stack question why thought work, though couldn't find in documentation) seem fire. (logging, debugging) if force isvalid() doesn't throw error either.

if manually run

validator.validate(this); 

then seem desired affect.

the unit tests wrote seem work, again in i'm manually running hibernates validator on thought implemented same bean validation jsf during validation?

it seems either there disconnect in mind kind of validations going on between standard beanvalidation , jsf validation, or have wrong in setup. of course there third option, i'm totally clueless.

thanks in advance.

that's because jsf not integrate bean validation via validator#validate, rather validator#validateproperty. latter allows validation of single properties , not support cross field validation. shortcoming of jsf bean validation integration. there discussions support class level constraints in future versions of integration, won't work. check jsf spec integration details.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -