Thursday, March 5, 2009

myfaces-extval-add-on - @BypassValidation for action methods

there is a new add-on for myfaces-extval.
it's hosted at [1] and a sample application is available at [2].

normally you have to validate all bound properties.
extval provides out-of-the-box a skip validation feature.
if one of the expressions of @SkipValidation returns true, validation of skipable validators gets canceled (the validation strategy has to be marked with @SkipValidationSupport).

anyway, sometimes you need actions which aren't immediate but they have to get executed without validation. therefore this add-on provides @BypassValidation

just add the add-on to your classpath and annotate these special action methods - example:

this simple case bypasses all skipable validations, if the annotated action method will be called.
-> e.g.: in this case @Required doesn't get validated whereas db constraints like nullable = false and length are validated in any case. (see the next usage, if you would like to bypass everything. however, please notice that it might lead to an exception if you try to save an invalid entity. so it's better to use all = false)

if you would like to bypass all validations use:
@BypassValidation(all = true)

furthermore, you can provide one or more optional el-expressions.
so it is possible to bypass validation just if one of the conditions returns true.

requirements: myfaces-extval 1.x.2-SNAPSHOT+