I have a JSF validator that checks whether a Container Number string conforms to the ISO-6346 specficiation.
It works fine, however I need to add some conditional processing in based on other values in the Bean where the Container Number comes from. This Bean can be of several different types.
Is there any way to access the Bean in the validator and perform operations on it? Ideally I'd love to keep it as a validator, however if there is no solution I'll have to implement the logic in the Bean before persisting.
I'm thinking something along the lines of:
public class ContainerNumberValidator implements javax.faces.validator.Validator {
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
Object bean = UIComponent.getMyBeanSomehowThroughAMagicMethod();
if(bean instanceof BeanA) {
//do this
} else if(bean instanceof BeanB) {
//do that
}
}
UPDATE: In many ways this is a similar problem to the validation of multiple fields at the same time. This code by BalusC is helpful.
Much appreciated.
D.