On Thu, May 17, 2012 at 5:38 PM, Pedro Quiñonez
<[email protected]> wrote:
> Of course I do,
>
> I try the BVal 0.4 and all its correct. With getter method works fine.

Hi Pedro,
  I had misunderstood you to say you were still encountering an error
with the 0.4 release.  Glad it's working for you after all.

>
> just one question, why  the API don´t work with inherited attributes even
> though they are marked as protected (only an existential doubt)

In section "7.1.1.2. Field-level overriding" of the Bean Validation
specification v1.0 it is stated that "If the name of the field does
not correspond to a field in the given bean a ValidationException is
raised."  Here "bean" refers to the type represented by the
surrounding <bean> element, and my interpretation is that the <field>
element is intended to correspond to the structure of an annotated
field on a given class.  You certainly can't annotate a field of a
superclass in Java code, but you *can* override that field's getter
method and annotate that--this approach would of course be the
analogous to using a <getter> element.

HTH,
Matt

>
> Thanks Matt,
>
>
>
> 2012/5/17 Matt Benson <[email protected]>
>>
>> Silly question:  does BaseDB2DataBean define a getter method for
>> acct_stat_cd, e.g.:
>>
>> public String getAcct_stat_cd() {
>>  return acct_stat_cd;
>> }
>>
>> Of course this method would be required for <getter> as well.  The
>> Bean Validation specification is designed to work with Java beans,
>> after all.  <field> is for fields declared on the <bean> class;
>> <getter> is for getter methods compliant with the Java beans
>> specification.  Looking at the code I fail to see how you would have a
>> problem with <getter> so long as one or both of these classes define
>> the getter method as I have described.
>>
>> Matt
>>
>> On Thu, May 17, 2012 at 2:52 PM, Pedro Quiñonez
>> <[email protected]> wrote:
>> > Thanks Matt,
>> >
>> > I tried using the <getter> form with the same results. Now I proves with
>> > BVal 0.4
>> >
>> > Regards!!
>> >
>> > 2012/5/17 Matt Benson <[email protected]>
>> >
>> >> Hi, Pedro.  In this case you should be using a <getter> instead of a
>> >> <field> in your XML-based constraint declarations (and, as it turns
>> >> out, that makes this a question for the user list ;) ).  It also looks
>> >> like you're not using the latest BVal release; we encourage you to
>> >> give Apache BVal 0.4 a try!
>> >>
>> >> Regards,
>> >> Matt
>> >>
>> >> On Thu, May 17, 2012 at 12:04 PM, Pedro Quiñonez
>> >> <[email protected]> wrote:
>> >> > hi team members,
>> >> >
>> >> > Over last date I tried to use the Apache Bean Validation with two
>> >> > beans,
>> >> A
>> >> > extends the attributes and methods from B. The constraint
>> >> > configuration
>> >> in
>> >> > the contraint.xml file, use constraints over the A class fields and
>> >> methods
>> >> > that extend from B class.
>> >> >
>> >> > At the moment to execute the example i get the next exception:
>> >> >
>> >> > *Caused by: javax.validation.ValidationException:
>> >> > gsa.dsc.jsr303.bean.module.MM_SA_DataBean does not contain the
>> >> > fieldType
>> >> > acct_stat_cd*
>> >> >    at
>> >> >
>> >>
>> >> org.apache.bval.jsr303.xml.ValidationMappingParser.processFieldLevel(ValidationMappingParser.java:360)
>> >> >    at
>> >> >
>> >>
>> >> org.apache.bval.jsr303.xml.ValidationMappingParser.processMappingConfig(ValidationMappingParser.java:96)
>> >> >    at
>> >> >
>> >>
>> >> org.apache.bval.jsr303.ApacheValidatorFactory.configure(ApacheValidatorFactory.java:121)
>> >> >    at
>> >> >
>> >>
>> >> org.apache.bval.jsr303.ApacheValidatorFactory.<init>(ApacheValidatorFactory.java:105)
>> >> >
>> >> > The question is, the bean validation support validations over fields
>> >> > and
>> >> > methods that are extends from one class base?
>> >> >
>> >> > public class *BaseDB2DataBean *{
>> >> >
>> >> >    /** Variable estatus cuenta */
>> >> >    protected String acct_stat_cd = null;
>> >> >
>> >> > }
>> >> >
>> >> >
>> >> > *MM_SA_DataBean* extends *BaseDB2DataBean*{
>> >> >
>> >> > }
>> >> >
>> >> > *sa-constraints.xml*
>> >> >    <bean class="gsa.dsc.jsr303.bean.module.MM_SA_DataBean">
>> >> >
>> >> >                <field name="acct_stat_cd">
>> >> >
>> >> >            <constraint
>> >> > annotation="javax.validation.constraints.NotNull"
>> >> />
>> >> >
>> >> >                    <constraint
>> >> > annotation="javax.validation.constraints.Pattern">
>> >> >                        <element name="regexp">
>> >> >                            <value>AC</value>
>> >> >                        </element>
>> >> >                    </constraint>
>> >> >                </field>
>> >> >     </bean>
>> >> >
>> >> >
>> >> >
>> >> >    public static void main(String[] args) {
>> >> >        Validator validator =
>> >> > Jsr303ValidatorFactory.SINGLE_INSTANCE.getValidator();
>> >> >
>> >> >        MM_SA_DataBean bean = new MM_SA_DataBean();
>> >> >
>> >> >        bean.setAcct_stat_cd("DE");
>> >> >        bean.setPlattform("MOVISTAR");
>> >> >        bean.setTechnology("4G");
>> >> >
>> >> >        Set<ConstraintViolation<MM_SA_DataBean>> result = null;
>> >> >        Iterator<ConstraintViolation<MM_SA_DataBean>> it = null;
>> >> >
>> >> >            long init = System.currentTimeMillis();
>> >> >            result = validator.validate(bean);
>> >> >            long end = System.currentTimeMillis();
>> >> >
>> >> >            System.out.println("Tiempo ejecución: [" + (end - init)+
>> >> > "]");
>> >> >
>> >> >        it = result.iterator();
>> >> >
>> >> >        while(it.hasNext()){
>> >> >            ConstraintViolation<MM_SA_DataBean> bean1 = it.next();
>> >> >            System.out.println("Valor:" + bean1.getInvalidValue() + "
>> >> > Mensaje:" + bean1.getMessage());
>> >> >        }
>> >> >    }
>> >>
>
>

Reply via email to