Validation

View: New views
4 Messages — Rating Filter:   Alert me  

Validation

by Carol_it :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi!
I am newbie and I would like to create custom validation.
I would like to retrieve some information from the db and then use these informations in my validation.
I have three entities Author, Book and Publisher, for the user's site and one entity for the admin's site, Validation.
I would like to retrieve info from the Validation entity to validate, for example, a property in Book entity.
I'm using Trails 1.1
How can I do that?
Thanks all!!!


------------------------------------------------------
Leggi GRATIS le tue mail con il telefonino i-mode™ di Wind
http://i-mode.wind.it/


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: Validation

by Kalle Korhonen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

So in other words, you want to create a dynamic validation criteria? Note that all of the built-in validation support uses static criteria, like @Email, @NotNull et as opposed to dynamic rules, which will make your case far more complex. I'd first consider your validation use case: do you need to make it generic or are you going to use it only on a few pages? If the latter is the case, I wouldn't worry about trying to make your validation as an annotation, but just to implement in a page, overriding the getClassDescriptor() and/or save() method of a Trails ModelPage. In the classDescriptor you can get a hold of the default classdescriptor, the obtain the instance of Validation entity and tweak the class and property descriptors to achieve the desired validation. Similarly, in save() you could obtain a HibernateValidationDelegate and add new ValidatorException instances to it.

All of this would almost certainly require you to browse the Trails source code and understand how things are done to see what's the best way to achieve what you want. This doesn't necessarily require a lot of code, but it's certainly not the easiest task to write for a newcomer. If you find yourself writing a lot of code for this, you are almost certainly doing something "wrong" or not the easiest possible way. You might get more help if you describe your use case better: what type of validation you are looking for ( e.g. just empty fields or something more complex?) and what do you think the Validation entity and its UI should look like (for the admin)?

If you are imaging some generic annotation for dynamic validation, you should start by defining a syntax for it first.

Kalle


On 10/8/07, carol.i <carol.i@...> wrote:
Hi!
I am newbie and I would like to create custom validation.
I would like to retrieve some information from the db and then use these informations in my validation.
I have three entities Author, Book and Publisher, for the user's site and one entity for the admin's site, Validation.
I would like to retrieve info from the Validation entity to validate, for example, a property in Book entity.
I'm using Trails 1.1
How can I do that?
Thanks all!!!


------------------------------------------------------
Leggi GRATIS le tue mail con il telefonino i-mode™ di Wind
http://i-mode.wind.it/


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email



Parent Message unknown Re: Validation

by Carol_it :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

First of all thanks for your help!!!

The UI for the Validation entity must have this properties:
field, to indicate a property in the others beans, for example price in Book;
value, an integer
op, < or > or =
opBool, and (optional)
value, an integer (optional)
op, < or > or = (optional)


An example is that the admin can set this validation rule for the books' price:

price: > 10 AND < 30

When the user tries to insert a new book with price=9 the application will have to generate a validation error.

My custom validation has to take place at insert time and edit time.

Thanks!

Carol






> So in other words, you want to create a dynamic validation criteria? Note
> that all of the built-in validation support uses static criteria, like
> @Email, @NotNull et as opposed to dynamic rules, which will make your case
> far more complex. I'd first consider your validation use case: do you need
> to make it generic or are you going to use it only on a few pages? If the
> latter is the case, I wouldn't worry about trying to make your validation as
> an annotation, but just to implement in a page, overriding the
> getClassDescriptor() and/or save() method of a Trails ModelPage. In the
> classDescriptor you can get a hold of the default classdescriptor, the
> obtain the instance of Validation entity and tweak the class and property
> descriptors to achieve the desired validation. Similarly, in save() you
> could obtain a HibernateValidationDelegate and add new ValidatorException
> instances to it.
>
> All of this would almost certainly require you to browse the Trails source
> code and understand how things are done to see what's the best way to
> achieve what you want. This doesn't necessarily require a lot of code, but
> it's certainly not the easiest task to write for a newcomer. If you find
> yourself writing a lot of code for this, you are almost certainly doing
> something "wrong" or not the easiest possible way. You might get more help
> if you describe your use case better: what type of validation you are
> looking for (e.g. just empty fields or something more complex?) and what do
> you think the Validation entity and its UI should look like (for the admin)?
>
> If you are imaging some generic annotation for dynamic validation, you
> should start by defining a syntax for it first.
>
> Kalle
>
>
> On 10/8/07, carol.i <carol.i@...> wrote:
> >
> > Hi!
> > I am newbie and I would like to create custom validation.
> > I would like to retrieve some information from the db and then use these
> > informations in my validation.
> > I have three entities Author, Book and Publisher, for the user's site and
> > one entity for the admin's site, Validation.
> > I would like to retrieve info from the Validation entity to validate, for
> > example, a property in Book entity.
> > I'm using Trails 1.1
> > How can I do that?
> > Thanks all!!!
> >
> >
> > ------------------------------------------------------
> > Leggi GRATIS le tue mail con il telefonino i-modeTM di Wind
> > http://i-mode.wind.it/
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> >
>


------------------------------------------------------
Leggi GRATIS le tue mail con il telefonino i-mode™ di Wind
http://i-mode.wind.it/


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Re: Validation

by Kalle Korhonen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok, so I'd do this in pieces. First, try out Hibernate's @Min and @Max to see how they behave, overriding the message property of the annotation if you are not happy with the default. Note that you cannot use these in your implementation because annotations are bound to the class and your use cases requires that you'd be allowed to enter some type of dynamic expression as a value of a property annotation which Hibernate annotations do not support (Seam annotations do to some extent). Then try to get the same behavior by re-creating the InvalidStateExpression manually in your overridden save() method of your custom edit page. See the source of HibernateValidationDelegate.record(); that should help you. Finally, add fetching of the Validation instance in the same save() method and change it to conditionally create exceptions based on its values.

Insert and edit uses the same edit page. If you only need this functionality on this particular page, I'd implement it in that custom page only.

One other thing to consider is how you want a validation to be associated with a book or its property. Direct associations with Validation and Book wouldn't work for inserts. It seems to me that you might want something like a book class or type that you'd associate with a new book instance, and have @ManyToOne from Validation to a BookType in place. Then you could use this association to retrieve all validation rules for a particular book type.

Kalle

On 10/8/07, carol.i <carol.i@...> wrote:
First of all thanks for your help!!!

The UI for the Validation entity must have this properties:
field, to indicate a property in the others beans, for example price in Book;
value, an integer
op, < or > or =
opBool, and (optional)
value, an integer (optional)
op, < or > or = (optional)


An example is that the admin can set this validation rule for the books' price:

price: > 10 AND < 30

When the user tries to insert a new book with price=9 the application will have to generate a validation error.

My custom validation has to take place at insert time and edit time.

Thanks!

Carol






> So in other words, you want to create a dynamic validation criteria? Note
> that all of the built-in validation support uses static criteria, like
> @Email, @NotNull et as opposed to dynamic rules, which will make your case
> far more complex. I'd first consider your validation use case: do you need
> to make it generic or are you going to use it only on a few pages? If the
> latter is the case, I wouldn't worry about trying to make your validation as
> an annotation, but just to implement in a page, overriding the
> getClassDescriptor() and/or save() method of a Trails ModelPage. In the
> classDescriptor you can get a hold of the default classdescriptor, the
> obtain the instance of Validation entity and tweak the class and property
> descriptors to achieve the desired validation. Similarly, in save() you
> could obtain a HibernateValidationDelegate and add new ValidatorException
> instances to it.
>
> All of this would almost certainly require you to browse the Trails source
> code and understand how things are done to see what's the best way to
> achieve what you want. This doesn't necessarily require a lot of code, but
> it's certainly not the easiest task to write for a newcomer. If you find
> yourself writing a lot of code for this, you are almost certainly doing
> something "wrong" or not the easiest possible way. You might get more help
> if you describe your use case better: what type of validation you are
> looking for (e.g. just empty fields or something more complex?) and what do
> you think the Validation entity and its UI should look like (for the admin)?
>
> If you are imaging some generic annotation for dynamic validation, you
> should start by defining a syntax for it first.
>
> Kalle
>
>
> On 10/8/07, carol.i <carol.i@...> wrote:
> >
> > Hi!
> > I am newbie and I would like to create custom validation.
> > I would like to retrieve some information from the db and then use these
> > informations in my validation.

> > I have three entities Author, Book and Publisher, for the user's site and
> > one entity for the admin's site, Validation.
> > I would like to retrieve info from the Validation entity to validate, for
> > example, a property in Book entity.
> > I'm using Trails 1.1
> > How can I do that?
> > Thanks all!!!
> >
> >
> > ------------------------------------------------------
> > Leggi GRATIS le tue mail con il telefonino i-modeTM di Wind
> > http://i-mode.wind.it/
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> >
>


------------------------------------------------------
Leggi GRATIS le tue mail con il telefonino i-mode™ di Wind
http://i-mode.wind.it/


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email