Search in sources :

Example 16 with ValidatorException

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);
    }
}
Also used : ValidatorException(javax.faces.validator.ValidatorException) FacesMessage(javax.faces.application.FacesMessage)

Example 17 with ValidatorException

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);
    }
}
Also used : ValidatorException(javax.faces.validator.ValidatorException) FacesMessage(javax.faces.application.FacesMessage)

Example 18 with ValidatorException

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));
    }
}
Also used : ValidatorException(javax.faces.validator.ValidatorException) UIInput(javax.faces.component.UIInput) FacesMessage(javax.faces.application.FacesMessage)

Example 19 with ValidatorException

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);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ValidatorException(javax.faces.validator.ValidatorException) UIComponent(javax.faces.component.UIComponent) FacesMessage(javax.faces.application.FacesMessage)

Example 20 with ValidatorException

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);
    }
}
Also used : ValidatorException(javax.faces.validator.ValidatorException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) FacesMessage(javax.faces.application.FacesMessage)

Aggregations

FacesMessage (javax.faces.application.FacesMessage)24 ValidatorException (javax.faces.validator.ValidatorException)24 UIInput (javax.faces.component.UIInput)5 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 AttributeValidation (org.gluu.model.attribute.AttributeValidation)2 Period (com.artezio.arttime.datamodel.Period)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 UIComponent (javax.faces.component.UIComponent)1 FacesContext (javax.faces.context.FacesContext)1 Validator (javax.faces.validator.Validator)1 Part (javax.servlet.http.Part)1 ConstraintViolation (javax.validation.ConstraintViolation)1 TenantDomainMismatchException (org.alfresco.repo.tenant.TenantDomainMismatchException)1 GluuAttribute (org.gluu.model.GluuAttribute)1 AttributeDataType (org.gluu.model.attribute.AttributeDataType)1 AttributeService (org.gluu.oxtrust.service.AttributeService)1