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].

[intro]
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

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


@BypassValidation
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.
@BypassValidation(
condition="#{currentUserRole.privileged}")


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

[1] http://code.google.com/p/os890/source/browse/#svn/trunk/java/web/jsf/extval/bypass_validation

[2] http://code.google.com/p/os890/source/browse/#svn/trunk/java/web/jsf/extval/examples/basic/demo_009