-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: XML validation is not working
PostPosted: Tue Oct 15, 2013 11:08 am 
Beginner
Beginner

Joined: Mon Sep 20, 2010 2:35 am
Posts: 20
Hi All,

I am testing bean validation using XMl and here is code from my
Code:
validation.xml


Code:
<?xml version="1.0" encoding="UTF-8"?>
<validation-config
    xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configurationvalidation-configuration-1.0.xsd">
    <constraint-mapping>org/demo/actions/modeldriven.xml</constraint-mapping>
</validation-config>


and modeldriven.xml have following data

Code:
<constraint-mappings
xmlns="http://jboss.org/xml/ns/javax/validation/mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.0.xsd">
 
    <bean class="com.raisonne.bd.dto.donor.DonorProfileDTOModel" ignore-annotations="true">
        <field name="name">
            <constraint annotation=" javax.validation.constraints.NotNull"/>
        </field>
       
         <field name="dateOfBirth">
            <constraint annotation=" org.hibernate.validator.constraints.NotBlank"/>
        </field>
          <field name="gender">
            <constraint annotation=" org.hibernate.validator.constraints.NotBlank"/>
        </field>
       
         <field name="weight">
            <constraint annotation="javax.validation.constraints.NotNull"/>
              <constraint annotation="javax.validation.constraints.Min">
               <element name="value">45</element>
             
              </constraint>
         </field>
       
        <field name="mobile">
            <constraint annotation=" javax.validation.constraints.Size"/>
        </field>
     
    </bean>
   
</constraint-mappings>



I tried every way, but seems like hibernate validator is not picking up modeldriven.xml.I tested with fully qualified class name like
Code:
<bean class="com.raisonne.bd.dto.donor.DonorProfileDTOModel" ignore-annotations="true">
and even with setting default package name like

Code:
<default-package>com.raisonne.bd.dto.donor</default-package>
<bean class="DonorProfileDTOModel" ignore-annotations="true">


This is what i am getting in server console
Code:
INFO (org.hibernate.validator.internal.xml.ValidationXmlParser:191) - HV000007: META-INF/validation.xml found. Parsing XML based configuration.

Not sure why it is not including modeldriven.xml file

Seems like nothing is working.
Can any one point me where i am doing wrong..


Top
 Profile  
 
 Post subject: Re: XML validation is not working
PostPosted: Tue Oct 15, 2013 3:43 pm 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi,

Do you get any sort of exception or are the XML based constraints silently ignored? Some more questions:

* Do you see something like "Trying to open input stream for ...modeldriven.xml" in your output? If that's the case the file at least gets parsed.
* How do you bootstrap your validator?
* Which version of HV is this?

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: XML validation is not working
PostPosted: Tue Oct 15, 2013 10:34 pm 
Beginner
Beginner

Joined: Mon Sep 20, 2010 2:35 am
Posts: 20
Hi Gunnar,

I am able to solve issue.Hibernate was able to locate as well parse XML file but i was not placing @valid annotation on my Bean model as i was thinking that in case of XML validation, we need not to have this annotation.

Placing @valid on bean object solved this issue.


Thanks
Umesh


Top
 Profile  
 
 Post subject: Re: XML validation is not working
PostPosted: Wed Oct 16, 2013 3:18 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Ok, great that it's working now.

Note that you also can mark elements for cascaded validation via XML by specifying the <valid/> element. Do so you should be able to work without using any annotations at all.

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.