1

I am writing one model class in spring mvc. I want to do domain validation.

In domain class I have 3 variables say isABCApplicable,abcValue1,abcValue2:

private Boolean isABCApplicable;

private BigDecimal abcValue1;

private BigDecimal abcValue2;

.......getters and setters.........

Now my aim is :

If isABCApplicable is true then i want to make abcValue1 as

@NotNull
 abcValue1 

and

@NotNull 
abcValue2

Is there any way to achieve this?

masted
  • 1,211
  • 2
  • 8
  • 14
JOHND
  • 2,597
  • 6
  • 27
  • 35

2 Answers2

1

I believe this is possible by bytecode instrumentation. ASM is one such tool you can manipulate Java bytecode with. Have a look at http://asm.ow2.org/index.html

heikkim
  • 2,955
  • 2
  • 24
  • 34
1

Why do you want use annotations?
Create your own DataBinder for your model-object and do all validation in object constructor.
Or if you realy want annotations, you can write your own constraint like @NotNullIfApplicable, see Cross field validation with Hibernate Validator (JSR 303) for details.

Community
  • 1
  • 1
masted
  • 1,211
  • 2
  • 8
  • 14