use of javax.faces.validator.ValidatorException in project dataverse by IQSS.
the class SendFeedbackDialog method validateUserSum.
public void validateUserSum(FacesContext context, UIComponent component, Object value) throws ValidatorException {
if (op1 + op2 != (Long) value) {
// TODO: Remove this English "Sum is incorrect" string. contactFormFragment.xhtml uses contact.sum.invalid instead.
FacesMessage msg = new FacesMessage("Sum is incorrect, please try again.");
msg.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(msg);
}
}
use of javax.faces.validator.ValidatorException in project dataverse by IQSS.
the class SendFeedbackDialog method validateUserEmail.
public void validateUserEmail(FacesContext context, UIComponent component, Object value) throws ValidatorException {
if (!EmailValidator.getInstance().isValid((String) value)) {
FacesMessage msg = new FacesMessage("Invalid email.");
msg.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(msg);
}
}
use of javax.faces.validator.ValidatorException in project dataverse by IQSS.
the class RequiredCheckboxValidator method validate.
@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
if (value.equals(Boolean.FALSE)) {
String requiredMessage = ((UIInput) component).getRequiredMessage();
if (requiredMessage == null) {
Object label = component.getAttributes().get("label");
if (label == null || (label instanceof String && ((String) label).length() == 0)) {
label = component.getValueExpression("label");
}
if (label == null) {
label = component.getClientId(context);
}
requiredMessage = MessageFormat.format(UIInput.REQUIRED_MESSAGE_ID, label);
}
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage));
}
}
use of javax.faces.validator.ValidatorException in project rubia-forums by flashboss.
the class LengthValidator method validate.
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
// A check whether it is post submition or preview action. If not
// validators are not executed.
FacesContext fc = getCurrentInstance();
Map<String, String> reqParams = fc.getExternalContext().getRequestParameterMap();
if (!(reqParams.keySet().contains("post:Preview") || reqParams.keySet().contains("post:Submit"))) {
return;
}
UIComponent formComp = component.getParent();
UIComponent validatedComp = getComponentToValidation(formComp);
if (validatedComp.getAttributes().get("value") == null || validatedComp.getAttributes().get("value").toString().trim().length() < 1) {
FacesMessage message = new FacesMessage();
message.setDetail(getBundleMessage(BUNDLE_NAME, getMessage()));
message.setSummary(getBundleMessage(BUNDLE_NAME, getMessage()));
message.setSeverity(SEVERITY_ERROR);
throw new ValidatorException(message);
}
}
use of javax.faces.validator.ValidatorException in project opentheso by miledrousset.
the class UrlValidator method validate.
@Override
public void validate(FacesContext facesContext, UIComponent component, Object value) throws ValidatorException {
StringBuilder url = new StringBuilder();
String urlValue = value.toString();
if (!urlValue.startsWith("http://", 0)) {
url.append("http://");
}
url.append(urlValue);
try {
new URI(url.toString());
} catch (URISyntaxException e) {
FacesMessage msg = new FacesMessage("URL validation failed", "Invalid URL format");
msg.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(msg);
}
}
Aggregations