I am using Bean Validation in my JSF project. Now I have come across a situation in which I would like to validate a method ONLY when a preceding method is validated.
I will give an example:
@AssertTrue(message="{invalidCode}")
private boolean isValidActivationCode() { ... }
if(isValidActivationCode()) {
@AssertTrue(message="{alreadyActivated}")
private boolean isAlreadyActivated() { ... }
}
Since I will receive the Activation Code per parameter, I would like to validate it first. If it is not valid, it will cause a violation. If so, I cannot even check whether it is already activated (since the code is invalid). So, is it possible to achieve anything like above mentioned (the function of the if-statement, I do know this would no way work, but it shows what I am trying to accomplish).
Thanks in advance
Update
Workaround like Ravi K mentioned:
@AssertTrue(message="{invalidCode}")
private boolean isValidActivationCode() { ... }
@AssertTrue(message="{alreadyActivated}")
private boolean isAlreadyActivated() { return isValidActivationCode() ? ... : true; }
Though I wonder, is there a clean way to solve this? If nobody provides an answer soon, I will assume there is no clean solution for this and I will accept the workaround from Ravi K as the answer to this problem.