-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate Validator: Using constants in constraints.xml
PostPosted: Thu Dec 05, 2013 6:26 pm 
Newbie

Joined: Thu Dec 05, 2013 6:06 pm
Posts: 1
Hi all,

I am using Hibernate Validator as a JSR-303 validation provider and its xml style constraints descriptions.
So, I have a

Code:
<bean class="com.my.User" ignore-annotations="true">
  <field name="email">
         <constraint annotation="javax.validation.constraints.Pattern">
             <element name="regexp"><![CDATA[[A-Za-z0-9\._%+-]{1,64}@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}]]></element>
         </constraint>
  </field>
  .....
</bean>


I also have a separate class, which contains all my patterns

Code:
public final class Regexps {
  public static final String EMAIL_REGEXP = "A-Za-z0-9\._%+-]{1,64}@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}";
  ....
}


So, as you can see, I have two places, where email regexp is present, and I want only one place.

My question:
Is it possible to use the
public static final String EMAIL_REGEXP = "A-Za-z0-9\._%+-]{1,64}@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}" field inside the xml, so that
I could just refer to the contant string field.
So I would Like to have something like:
Code:
<bean class="com.my.User" ignore-annotations="true">
  <field name="email">
         <constraint annotation="javax.validation.constraints.Pattern">
             <element name="regexp">Regexps.EMAIL_REGEXP</element>
         </constraint>
  </field>
  .....
</bean>


By the way, it is possible via annotations
Code:
public class User {
   @Pattern(regexp = Regexps.EMAIL_REGEXP)   
   private String email;
}

But I cannot use annotations, because I use the legacy POJOs which I use for data transfering and cannot change the source code.


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

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.