-->
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.  [ 7 posts ] 
Author Message
 Post subject: Validate a value used to produce entity/entities
PostPosted: Tue May 29, 2007 6:53 am 
Newbie

Joined: Tue May 29, 2007 4:46 am
Posts: 6
Hello,

I'm using a String to build entities. How can I validate this String ?

Here is an example :

Code:
@Entity
class Question {
        [...]

        @OneToMany( cascade=CascadeType.ALL)
        private List< Option > options;
   
        transient String optionsText;

        public void setOptions(List<Option> options) {
                this.options = options;
      
                // convert options in optionsText
                [...]
        }

        public void setOptionsText(String optionsText) {
               // convert optionsText in options
               String lines[] = optionsText.split( separator );
               [...]
        }

        [...]
}

Code:
class Option {
        [...]
        @Length(min=1, max=50)
   private String text;
}


So I would like to validate all the produced options. I quickly imagined something like :
Code:
class Question {
        [...]

        @TransformationConstraint( "optionMaker" )
        transient String optionsText;


        @Transformator( "optionMaker" )
        public static List< Option > makeOptions( String optionsText ) {
             [...]
        }

        public void setOptionsText( String txt ) {
             // use makeOptions
             [...]
        }
}


The @Transformator annotation register a transformator with id optionMaker. Then we can use it in @TransformationConstraint.

Ok this is just an idea, maybe something easier / cleaner is possible.
Thanks for your comments.

Bruno


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 29, 2007 3:15 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I don't understand what you are trying to achieve, what @Transformator does?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 29, 2007 3:43 pm 
Newbie

Joined: Tue May 29, 2007 4:46 am
Posts: 6
Well, I'm writing a questionnaire maker. So the user can make questions. The questions may have options. I found convenient to create the options from a textarea (=String) using line-break to split them.

The problem now is validating this string in order to have valid generated options.

My thought was to define a converter/transformator for String to option list (here is the @Transformator annotation) and then tell the validator to use it for validating a property (@TransformationConstraint).

From the validator point of view : get the transformator with id "optionMaker", invoke it with the property and validate the result (which is an entity or entities).


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 29, 2007 3:45 pm 
Newbie

Joined: Tue May 29, 2007 4:46 am
Posts: 6
Well, I'm writing a questionnaire maker. So the user can make questions. The questions may have options. I found convenient to create the options from a textarea (=String) using line-break to split them.

The problem now is validating this string in order to have valid generated options.

My thought was to define a converter/transformator for String to option list (here is the @Transformator annotation) and then tell the validator to use it for validating a property (@TransformationConstraint).

From the validator point of view : get the transformator with id "optionMaker", invoke it with the property and validate the result (which is an entity or entities).


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 12:28 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
So I guess you are looking for @Valid on the collection, it will validate each Option object recursively

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 3:01 pm 
Newbie

Joined: Tue May 29, 2007 4:46 am
Posts: 6
Ok that sounds good ! I'll try tomorrow. Thank you.

BTW I posted few messages on the french forum (about the validator again) but everything has been removed. I think because I replied to a SPAM ...
The old account was mustaghattack


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 31, 2007 1:25 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Why on earth would you reply to a spam??

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.