I have one pojo class with name LoanForm with few fields:String loanType;String source;String amount;
I created a custom annotation for loanType. Below is the code.Next I created another class as validator LoanTypeConstraintValidator. Below is the code.The above annotation is checking if loantype is blank or not. I have 3 sources let's say A,B,C. Now if source is A and user submits the form an error message will get display. But if source is B even if loanType is null or blank form should get submitted. So I am stuck at how to access source field in this LoanType custom annotation and how to check if source is A or B or C.
Here is my Custom Validator class code:
public class LoanTypeConstraintValidator
implements ConstraintValidator<LoanType, Integer>
{
public void initialize(LoanType loanType)
{
}
@Override
public boolean isValid(Integer loanTypeField, ConstraintValidatorContext arg1)
{
if (loanTypeField == null)
{
return true;
}
else
{
return false;
}
}
}