Tuesday, March 31, 2009

myfaces-extval-add-on - @BypassValidationController

the bypass validation add-on for extval was updated!

beyond the action-method based bypass it's possible to bypass validation with an annotation which is similar to a view-controller annotation. anyway, it works the opposite way round. if the annotation is used validation is bypassed.

you can use the annotation on the first bean (= page/backing bean), the first property (of the page/backing bean), the last base object (owner of the property) and the bound property.

that means something like:
#{pageBean.bean1.bean2.person.firstName}
the green parts are possible targets for @BypassValidationController

a simple example:
that leads to:

1) bypassed extval-validation for every property bound via: #{personPage2. ...}

attention: only skipable validations are bypassed by default. so e.g. jpa based validation continues to work. if you would like to really bypass everything, you have to use:
@BypassValidationController(@ViewId(all = true))
instead.

2) bypassed extval-validation for every property bound via: #{personPage2.person ...}
but only for the view-id "/pages/new_person2.xhtml" + the given condition is true.

it's important to mention that the 4 possible targets for @BypassValidationController are optional. e.g. it's possible to annotate a property without annotating the class itself. furthermore, there are useful default values for all attributes.

myfaces-extval and icefaces

i did some quick tests with icefaces and extval.

behind the scenes icefaces does some tricks.
so it's required to deactivate 2 extval mechanisms. with this workaround a hello world icesfaces started working with myfaces extval.

#1: deactivate the extval el-resolver via web.xml context-parameter:

org.apache.myfaces.extensions.validator.DEACTIVATE_EL_RESOLVER
true


#2 switch or deactivate the default renderer proxy implementation via a extval-startup-listener.
deactivate it via:
...
protected void init()
{
ExtValContext.getContext().addGlobalProperty(ExtValRendererProxy.KEY, null);
}
...

i haven't tried more complex applications. you are welcome to try it out :)
if you find some issues please report them.

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