public void assertValid(T value) { InvalidStateException lastException = null; boolean isValid = false; for (Validator<T> v : validators) { if (v.isEligible(value)) { try { v.assertValid(value); isValid = true; break; } catch (InvalidStateException e) { lastException = e; } } } if (!isValid) { if (lastException != null) { throw lastException; } else { throw new InvalidStateException(messageProducer.getMessage(invalidFormat)); } } }
public void assertValid(T value) { InvalidStateException lastException = null; boolean isValid = false; for (Validator<T> v : validators) { if (v.isEligible(value)) { try { v.assertValid(value); isValid = true; break; } catch (InvalidStateException e) { lastException = e; } } } if (!isValid) { if (lastException != null) { throw lastException; } else { throw new InvalidStateException(messageProducer.getMessage(invalidFormat)); } } }
public void validate(final FacesContext facesContext, final UIComponent uiComponent, final Object value) throws ValidatorException { ResourceBundle bundle = resourceBundleFinder.getForCurrentLocale(facesContext); ResourceBundleMessageProducer producer = new ResourceBundleMessageProducer(bundle); try { br.com.caelum.stella.validation.Validator<String> validator; try { String estadoValue; if (estado == null) { ValueHolder estadoValueHolder = (ValueHolder) facesContext.getViewRoot().findComponent( estadoComponentId); estadoValue = estadoValueHolder.getValue().toString(); } else { estadoValue = estado; } validator = Estado.valueOf(estadoValue).getIEValidator(producer, formatted); } catch (Exception ex) { validator = new RejectAllValidator<String>(producer, IEError.UNDEFINED_STATE); } validator.assertValid(value.toString()); } catch (InvalidStateException e) { List<ValidationMessage> messages = e.getInvalidMessages(); String firstErrorMessage = messages.get(0).getMessage(); registerAllMessages(facesContext, uiComponent, messages.subList(1, messages.size())); throw new ValidatorException(new FacesMessage(firstErrorMessage)); } }
public void validate(final FacesContext facesContext, final UIComponent uiComponent, final Object value) throws ValidatorException { ResourceBundle bundle = resourceBundleFinder.getForCurrentLocale(facesContext); ResourceBundleMessageProducer producer = new ResourceBundleMessageProducer(bundle); try { br.com.caelum.stella.validation.Validator<String> validator; try { String estadoValue; if (estado == null) { ValueHolder estadoValueHolder = (ValueHolder) facesContext.getViewRoot().findComponent( estadoComponentId); estadoValue = estadoValueHolder.getValue().toString(); } else { estadoValue = estado; } validator = Estado.valueOf(estadoValue).getIEValidator(producer, formatted); } catch (Exception ex) { validator = new RejectAllValidator<String>(producer, IEError.UNDEFINED_STATE); } validator.assertValid(value.toString()); } catch (InvalidStateException e) { List<ValidationMessage> messages = e.getInvalidMessages(); String firstErrorMessage = messages.get(0).getMessage(); registerAllMessages(facesContext, uiComponent, messages.subList(1, messages.size())); throw new ValidatorException(new FacesMessage(firstErrorMessage)); } }