You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Andrea Cerfogli <a....@gmail.com> on 2015/03/19 08:08:05 UTC
Problem with Date data type ConstraintValidator
Hello,
I'm using Tapestry 5.4 beta 27 on java 1.7.0_76 with Windows 8.1.
I'm not sure this is the right place where describe a potential bug.
I put my very simplified class.
I have an entity with two Date fields:
@Entity
@Table(name = "testparent", schema = "phoenix")
public class TestParent implements Serializable{
@Property
@ValidateDb (name="V1")
@Column(name = "F7dateReq")
public Date f7datereq;
@Property
@ValidateDb (name="V2")
@Column(name = "F14datetimeReq")
public Date f14datetimeReq;
}
and a custom ValidateDb ConstraintValidator that ensure that date values
are mandatory:
@Constraint(validatedBy = ValidateDbValidator.class)
@Target({ METHOD, FIELD, ANNOTATION_TYPE})
@Retention(RUNTIME)
@Documented
public @interface ValidateDb {
String message() default "{com.acme.constraint.Range.message}";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
String name() default "";
}
public class ValidateDbValidator implements ConstraintValidator<ValidateDb,
Object> {
@Override
public void initialize(ValidateDb constraintAnnotation) {
}
public boolean isValid(Object value, ConstraintValidatorContext
context) {
String errorMessage=null;
if (value==null)
errorMessage="{validateDb.constraint.notNull}";
context.disableDefaultConstraintViolation();
if (errorMessage==null || "".equals(errorMessage.trim()))
{
context.buildConstraintViolationWithTemplate("").addConstraintViolation();
return true;
}
else
{
context.buildConstraintViolationWithTemplate(errorMessage).addConstraintViolation();
return false;
}
}
}
I'm using the standard bean edit form and when I press the "Save" button,
the alert message appears in this way
[image: Immagine in linea 1]
In other words I get just one message referring the wrong input component
while I should get two distinct error messages, one for each field.
If I use two String fields instead of date fields, the messages are right
[image: Immagine in linea 2]
Re: Problem with Date data type ConstraintValidator
Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Thu, 19 Mar 2015 04:08:05 -0300, Andrea Cerfogli <a....@gmail.com>
wrote:
>
> Hello,
Hi!
> I'm using Tapestry 5.4 beta 27 on java 1.7.0_76 with Windows 8.1.
> I'm not sure this is the right place where describe a potential bug.
I believe this should have been posted to the users mailing list first.
> I put my very simplified class.
>
> I have an entity with two Date fields:
> @Entity
>
> @Table(name = "testparent", schema = "phoenix")
>
> public class TestParent implements Serializable{
>
> @Property
> @ValidateDb (name="V1")
> @Column(name = "F7dateReq")
> public Date f7datereq;
>
> @Property
> @ValidateDb (name="V2")
> @Column(name = "F14datetimeReq")
> public Date f14datetimeReq;
> }
>
> and a custom ValidateDb ConstraintValidator that ensure that date values
> are mandatory:
>
>
> @Constraint(validatedBy = ValidateDbValidator.class)
> @Target({ METHOD, FIELD, ANNOTATION_TYPE})
> @Retention(RUNTIME)
> @Documented
> public @interface ValidateDb {
> String message() default "{com.acme.constraint.Range.message}";
>
> Class<?>[] groups() default {};
>
> Class<? extends Payload>[] payload() default {};
>
> String name() default "";
> }
>
>
> public class ValidateDbValidator implements
> ConstraintValidator<ValidateDb, Object> {
> @Override
> public void initialize(ValidateDb constraintAnnotation) {
> }
>
> public boolean isValid(Object value, ConstraintValidatorContext
> context) {
> String errorMessage=null; if (value==null)
> errorMessage="{validateDb.constraint.notNull}";
>
> context.disableDefaultConstraintViolation(); if
> (errorMessage==null || "".equals(errorMessage.trim()))
> {
> context.buildConstraintViolationWithTemplate("").addConstraintViolation();
> return true; }
> else
> {
> context.buildConstraintViolationWithTemplate(errorMessage).addConstraintViolation();
> return false;
> }
> }
> }
>
>
> I'm using the standard bean edit form and when I press the "Save"
> button, the alert message appears in this way
> In other words I get just one message referring the wrong input
> component while I should get two distinct error messages, >one for each
> field.
>
> If I use two String fields instead of date fields, the messages are right
>
>
>
--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br