Hi Gerald,

first, welcome to the mailing list.

a) about the multifield ConstraintValidator.
You see the messages twice since you set 2 ConstraintViolation on the
context.
And to my knowledge there is no link between the propertyPath and the
component the message is intended to.  Not in the JSR303 and thus not in
the ExtVal support for it.
Can you please point us to the info (spec) if we are wrong.

b) Validation in 2 phases
This is due to the fact that you need all the field values in the model
before you can do any multifield validation.

Within the Process Validation phase, the JSF validations on a single field
takes place (required, within limits, etc ...). ExtVal then also processes
the BeanValidation annotations which are placed on the field/method like
@Size, @NotNull etc ...

But the multi field validation can't be performed at that moment because it
requires that the screen values are propagated to the managedBean.  This is
because the ConstraintValidator needs the object populated with the values
to do his checks.
This means it can be only done after the 'update model values' phase and
thus only performed when no problems are found yet.


Hopes this clarifies the things a bit.

Regards
Rudy

-- 
Rudy De Busscher
http://www.c4j.be


On 7 March 2012 03:21, Gerald Turner <[email protected]> wrote:

> Hi myfaces-users, I sent the following email directly to Gerhard
> Petracek and he pointed me to the mailing list, mentioned that there is
> usually a short discussion before opening a JIRA ticket.
>
> Gerald Turner <[email protected]> writes:
>
> > Hello Gerhard, I apologize in advance if this is inappropriate to
> > email you a question directly — I'm having a hard time deciphering
> > what sort of support is available to the MyFaces project.
> >
> > I have a quick question: Should the ExtVal BV framework be able to
> > inspect javax.validation.ConstraintViolation<T> getPropertyPath and
> > getRootBean methods and affix the resulting FacesMessage to the
> > appropriate clientID?
> >
> > I've looked thru the ExtVal source and it seems that this bit if
> > detail in ConstraintViolation is discarded.  Should I report this in
> > JIRA as a feature request?
> >
> > Here's a terse example in case that question didn't make sense:
> >
> > Using JSR303 I have a multi-field ConstraintValidator on the
> > type/class level of a JPA entity.  The ConstraintValidator emits two
> > ConstraintViolations with propertyPath set, one for each field.  The
> > JSF page has a globalOnly h:messages and a h:message for each field.
> > The violation messages are rendered in the globalOnly component
> > (twice) and not rendered to the specific fields.
> >
> > § Entity:
> >
> >   @WidgetMutuallyExclusiveOptions
> >   @Entity
> >   class Widget {
> >
> >     private boolean option1;
> >     private boolean option2;
> >
> >   }
> >
> > § ConstraintValidator:
> >
> >   class WidgetMutuallyExclusiveOptionsValidator
> >       implements
> ConstraintValidator<WidgetMutuallyExclusiveOptions,Widget> {
> >
> >     private WidgetMutuallyExclusiveOptions anno;
> >
> >     public void initialize(WidgetMutuallyExclusiveOptions anno) {
> >       this.anno = anno;
> >     }
> >
> >     public isValid(Widget widget, ConstraintValidatorContext ctx) {
> >       if (widget.isOption1() && widget.isOption2()) {
> >         ctx.disableDefaultConstraintViolation();
> >         ctx.buildConstraintViolationWithTemplate(anno.message())
> >            .setNode("option1");
> >            .addConstraintViolation();
> >         ctx.buildConstraintViolationWithTemplate(anno.message())
> >            .setNode("option2");
> >            .addConstraintViolation();
> >         return false;
> >       }
> >       return true;
> >     }
> >
> >   }
> >
> > § Controller Bean:
> >
> >   @Named("edit")
> >   public WidgetEdit {
> >
> >     @BeanValidation(modelValidation=@ModelValidation(isActive=true))
> >     private Widget widget;
> >
> >     public Widget getWidget() {
> >       return widget;
> >     }
> >
> >     public void save() {
> >       …
> >     }
> >
> >   }
> >
> > § Partial JSF:
> >
> >   <h:form>
> >     <h:messages globalOnly="true"/>
> >     <h:panelGrid columns="3">
> >       <h:outputLabel value="Option #1" for="opt1"/>
> >       <h:selectBooleanCheckbox id="opt1" value="#{edit.widget.option1}"/>
> >       <h:message for="opt1"/>
> >       <h:outputLabel value="Option #2" for="opt2"/>
> >       <h:selectBooleanCheckbox id="opt2" value="#{edit.widget.option2}"/>
> >       <h:message for="opt2"/>
> >     </h:panelGrid>
> >     <h:commandButton value="Submit" actionListener="#{edit.save}"/>
> >   </h:form>
> >
> > Sorry, can't help myself, one more question: it seems that
> > field/method level validations are check in one pass, then type/class
> > level validations in a second pass only if the first pass succeeded.
> > For instance if I add @Size and @NotNull sorts of validations to the
> > Entity in addition to the multi-field @WidgetMutuallyExclusiveOptions,
> > I cannot get all the error messages rendered in one response, I have
> > to pass the @Size/@NotNull/etc. validations before seeing the
> > multi-field validation.  Is there a way of changing that behavior?  It
> > could be that ExtVal isn't handling my field validations, perhaps it's
> > the native JSF stack getting a crack at JSR303 before ExtVal's turn.
> >
> > BTW, I really appreciate ExtVal BV, I've spent the last several days
> > trying to debug why JSR303 isn't fully supported by JSF, considered
> > writing some glue that clones model objects but my project is getting
> > increasingly uglier!  ExtVal does the trick in one maven dependency +
> > one annotation on the JSF bean, nice!
>
> --
> Gerald Turner   Email: [email protected]   JID: [email protected]
> GPG: 0xFA8CD6D5  21D9 B2E8 7FE7 F19E 5F7D  4D0C 3FA0 810F FA8C D6D5
>

Reply via email to