Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Validation define array values in XML
PostPosted: Thu Nov 17, 2011 6:42 am 
Newbie

Joined: Thu Nov 17, 2011 6:39 am
Posts: 2
I'm trying to create a custom validation wherein I have defined the annotation to accept an array of Strings for example:

public @interface Enum {
String message() default "{}";

Class<?>[] groups() default {};

Class<? extends Payload>[] payload() default {};

String[] value();
}

where value is an array of Strings. In the annotation i can use it as @Enum(value={"ABC", "PQR"}) & i can also retrieve this information at runtime. But when i represent the same information in the xml format as.

<constraint annotation="com.customvalidation.Enum">
<element name="value">ABC</element>
<element name="value">PQR</element>
</constraint>

it doesn't work, does any body have idea on how to represent the array in XML..?


Top
 Profile  
 
 Post subject: Re: Validation define array values in XML
PostPosted: Fri Nov 18, 2011 3:40 am 
Newbie

Joined: Thu Nov 17, 2011 6:39 am
Posts: 2
Does anybody have any idea how to do this? I'm stuck at this point.


Top
 Profile  
 
 Post subject: Re: Validation define array values in XML
PostPosted: Sat Nov 19, 2011 8:22 am 
Hibernate Team
Hibernate Team

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

I think you would do that like this:

Code:
<constraint annotation="com.customvalidation.Enum">
  <element name="value">
    <value>ABC</value>
    <value>PQR</value>
  </element>


Here the "element" node refers to the member "value" of your annotation type "enum", while the inner "value" elements represent the array members of that "value" attribute.

You can find more information and also another example in section 7.1.1.4 of the BV specification.

--Gunnar

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 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.