myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gerhard Petracek <gerhard.petra...@gmail.com>
Subject Re: Re: Re: Re: cross field BeanValidation
Date Wed, 24 Aug 2011 12:30:49 GMT
HelloGroupValidationController is a backing-bean (= a controller for a
page). such a controller contains code which is related to a page (e.g. jsf
action methods, action listeners,... as well as the domain objects which are
used by the page).

in this demo there is a property called person and the class Person is
annotated with a class-level bv-constraint.
the minimum you have to use to trigger the validation of the class-level
bv-constraint is e.g.:

@BeanValidation(modelValidation = @ModelValidation(isActive = true))
private Person person = new Person();

that means: as soon as one property of person is bound to an input component
which gets validated, the whole person-object will be validated after the
update model-values phase.

as you see in the example, you can restrict the validation to a specific
page and/or bv-group.

fyi:
there are different possibilities where @BeanValidation can be used.
however, if this annotation doesn't fit to the design of your application,
you could write e.g. a custom tag-handler which
uses ExtValBeanValidationContext#addModelValidationEntry for adding an entry
to the context (based on the information provided via the tag-handler). btw.
we could create an extval add-on for it.

if you are just trying to implement simple cross-validation (in terms of
jsf) and class-level validation was just a workaround because you tried to
do everything with bv-constraints, you should think about the multi-field
form validation add-on (because it's easier for such use-cases).

regards,
gerhard

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces



2011/8/24 <win@lang-inet.de>

> Thanks it does compile now.
>
> I am really sorry but I have to ask again how can I enable the
> validation in JSF for
> my own class annotation? This example [1] seems to the most appropriate
> one to
> my problem. I have added the maven dependencies and now? (just writing
> this a
> class like HelloGroupValidationController in the example does not work
> and I'm not
> really understanding what this class is doing - is it a kind of
> interceptor for  the
> creating these objects?)
>
> [1]
>
> https://svn.apache.org/repos/asf/myfaces/extensions/validator/trunk/examples/h
> ello_bean-validation/
>
>
> > that's due to one of the transitive dependencies. i've created a jira
> issue
> > [1] which also shows an example for excluding such dependencies.
> >
> > regards,
> > gerhard
> >
> > [1] https://issues.apache.org/jira/browse/EXTVAL-136
> >
> > http://www.irian.at
> >
> > Your JSF powerhouse -
> > JSF Consulting, Development and
> > Courses in English and German
> >
> > Professional Support for Apache MyFaces
> >
> >
> >
> > 2011/8/23 <win@lang-inet.de>
> >
> > > OK I do now understand whats going on here - thanks
> > > But if I added all Maven dependencies I get compilation errors.
> > > It seems that the ExtVal version of the EntityManager does not have
> the
> > > method
> > > getCriteriaBuilder() but why?
> > >
> > > This code breaks:
> > > public List<T> findAll() {
> > >        javax.persistence.criteria.CriteriaQuery cq =
> > > getEntityManager().getCriteriaBuilder().createQuery();
> > >        cq.select(cq.from(entityClass));
> > >        return getEntityManager().createQuery(cq).getResultList();
> > > }
> > >
> > > (error: cannot find symbol)
> > >
> > >
> > > > yes - it works because jpa validates it again (per default). but
> it
> > > > shouldn't get to this point, because (as you see) jsf can't
> process it
> > > > automatically and some parts of your business logic might get
> executed
> > > as
> > > > well (before the first validation gets executed).
> > > >
> > > > fyi:
> > > > if you would like to use extval, please add the core explicitly.
> it's
> > > just
> > > > included as transitive dependency due to a workaround for the old
> > > build
> > > > setup. as soon as we have time for a full cleanup of the build
> files,
> > > it
> > > > will change for the releases afterwards.
> > > >
> > > > @generic support module: see [1]
> > > >
> > > > regards,
> > > > gerhard
> > > >
> > > > [1] http://www.mail-
> archive.com/users@myfaces.apache.org/msg57682.html
> > > >
> > > > http://www.irian.at
> > > >
> > > > Your JSF powerhouse -
> > > > JSF Consulting, Development and
> > > > Courses in English and German
> > > >
> > > > Professional Support for Apache MyFaces
> > > >
> > > >
> > > >
> > > > 2011/8/23 <win@lang-inet.de>
> > > >
> > > > > First of all thanks for the quick response.
> > > > > I checked out the examples and the wiki. But I don't understand
> why
> > > I
> > > > > should
> > > > > provide these extra possibility's for validation, because my
> > > constraint
> > > > > is working as
> > > > > mentioned in the primefaces forum post. It's all just about
> passing
> > > this
> > > > > result of
> > > > > validation inside the entity manager to JSF ?
> > > > >
> > > > > Regards
> > > > > Alesandro
> > > > >
> > > > > > hi alesandro,
> > > > > >
> > > > > > first of all: welcome @ myfaces!
> > > > > >
> > > > > > for cross-validation you need the property-validation module
> (!=
> > > > > > bean-validation) and for advanced bean-validation you need the
> > > > > > bean-validation module (+ the bv implementation of your
> choice).
> > > > > > in any case you need the core of extval. for primefaces it's
> also
> > > > > suggested
> > > > > > to use the generic support module.
> > > > > >
> > > > > > you can find hello world examples at [1]. furthermore, you
> might
> > > be
> > > > > > interested in the wiki [2] and a chapter about extval [3].
> both
> > > > > contain
> > > > > > detailed information about such topics.
> > > > > >
> > > > > > regards,
> > > > > > gerhard
> > > > > >
> > > > > > [1]
> > > > > >
> > > > >
> > > > >
> > >
> > >
>
> https://svn.apache.org/repos/asf/myfaces/extensions/validator/trunk/examples/
> > > > > > [2] https://cwiki.apache.org/confluence/display/EXTVAL
> > > > > > [3]
> > > > >
> > >
> http://people.apache.org/~gpetracek/myfaces/extval/extval_chapter.html
> > > > > >
> > > > > > http://www.irian.at
> > > > > >
> > > > > > Your JSF powerhouse -
> > > > > > JSF Consulting, Development and
> > > > > > Courses in English and German
> > > > > >
> > > > > > Professional Support for Apache MyFaces
> > > > > >
> > > > > >
> > > > > > 2011/8/23 <win@lang-inet.de>
> > > > > >
> > > > > > > Hello,
> > > > > > >
> > > > > > > I tried to make a cross field BeanValidation with a custom
> > > > > annotation.
> > > > > > > (based on JEE6 /
> > > > > > > JSF2) The validation works correct but it's not passed
to
> the
> > > JSF
> > > > > view.
> > > > > > > I wrote about
> > > > > > > this in the Primefaces forum
> > > > > > > http://forum.primefaces.org/viewtopic.php?f=3&t=14569
> > > > > > > . It would be nice if someone would have a look at this
> (maybe
> > > Iam
> > > > > just
> > > > > > > getting
> > > > > > > something basic wrong with ExtVal).
> > > > > > >
> > > > > > > Regards
> > > > > > > Alesandro
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > > >
> > >
> >
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message