|
|
|
|
|
|
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> {code}
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}"; .... } {code}
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
{code} public static final String EMAIL_REGEXP = "A-Za-z0-9\._%+-]{1,64}@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}"; {code}
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> {code}
By the way, it is possible via annotations
{code} public class User { @Pattern(regexp = Regexps.EMAIL_REGEXP) private String email; } {code}
But I cannot use annotations, because I use the legacy POJOs which I use for data transfering and cannot change the source code.
|
|
|
|
|
|