Example usage for org.apache.wicket.markup.html.form FormComponent error

List of usage examples for org.apache.wicket.markup.html.form FormComponent error

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.form FormComponent error.

Prototype

public void error(IValidationError error) 

Source Link

Document

Reports a validation error against this form component.

Usage

From source file:eu.uqasar.web.pages.qmtree.metric.QMMetricFormValidator.java

License:Apache License

@Override
public void validate(Form<?> form) {
    final FormComponent name = components[0];
    final FormComponent<Double> lowerLimit = components[1];
    final FormComponent<Double> upperLimit = components[2];

    Localizer loc = getLocalizer(form);//from w  w  w .  j a  v  a 2  s  .c o m
    String nameValue = Objects.stringValue(name.getInput(), true);

    if ("".equals(nameValue)) {
        name.error(loc.getString("form.name.required", name));
    } else if (nameValue.length() > 255) {
        name.error(loc.getString("form.name.max", name));
    }

    //         if (Double.valueOf(lowerLimit.getValue()) > Double.valueOf(upperLimit.getValue())){
    //            upperLimit.error(loc.getString("form.upperLimit.low", upperLimit));
    //         }
}

From source file:eu.uqasar.web.pages.qmtree.qmodels.QModelFormValidator.java

License:Apache License

@Override
public void validate(Form<?> form) {
    final FormComponent name = components[0];
    final FormComponent key = components[1];
    final boolean isNew = newEntity;
    final String oldKey = previousKey;

    Localizer loc = getLocalizer(form);/*from  w  w w  . j ava 2 s .c o m*/
    String f1Value = Objects.stringValue(name.getInput(), true);
    String f2Value = Objects.stringValue(key.getInput(), true);

    if ("".equals(f1Value)) {
        name.error(loc.getString("form.name.required", name));
    } else if (f1Value.length() > 255) {
        name.error(loc.getString("form.name.max", name));
    }
    if ("".equals(f2Value)) {
        key.error(loc.getString("form.key.required", key));
    }

    List<String> nodeKeyList = qmodelService.getAllNodeKeys();
    if (!previousKey.equals(f2Value) && !isNew && Collections.frequency(nodeKeyList, f2Value) >= 1) {
        key.error(loc.getString("form.key.repeated", key));
    } else if (!previousKey.equals(f2Value) && isNew && (Collections.frequency(nodeKeyList, f2Value) > 0)) {
        key.error(loc.getString("form.key.repeated", key));
    }
}

From source file:eu.uqasar.web.pages.qmtree.quality.indicator.QMQualityIndicatorFormValidator.java

License:Apache License

@Override
public void validate(Form<?> form) {
    final FormComponent name = components[0];
    final FormComponent<Double> lowerLimit = components[1];
    final FormComponent<Double> upperLimit = components[2];

    Localizer loc = getLocalizer(form);//w  w  w .  jav  a  2  s.  c  o  m
    String f1Value = Objects.stringValue(name.getInput(), true);
    if ("".equals(f1Value)) {
        name.error(loc.getString("form.name.required", name));
    } else if (f1Value.length() > 255) {
        name.error(loc.getString("form.name.max", name));
    }

    //         if (Double.valueOf(lowerLimit.getValue()) > Double.valueOf(upperLimit.getValue())){
    //            upperLimit.error(loc.getString("form.upperLimit.low", upperLimit));
    //         }
}

From source file:ontopoly.validators.ExternalValidation.java

License:Apache License

public static void validate(final FormComponent<String> component, final String value) {
    List<IValidator<String>> validators = component.getValidators();
    final IValidatable<String> validatable = new IValidatable<String>() {
        public void error(IValidationError error) {
            component.error(error);
        }//from   w ww  .ja  v a  2s  . co  m

        public String getValue() {
            return value;
        }

        public boolean isValid() {
            return component.isValid();
        }
    };

    IValidator<String> validator = null;
    boolean isNull = value == null;

    try {
        Iterator<IValidator<String>> iter = validators.iterator();
        while (iter.hasNext()) {
            validator = iter.next();
            if (isNull == false || validator instanceof INullAcceptingValidator)
                validator.validate(validatable);
            if (!component.isValid())
                break;
        }
    } catch (Exception e) {
        throw new WicketRuntimeException("Exception '" + e + "' occurred during validation "
                + validator.getClass().getName() + " on component " + component.getPath(), e);
    }
}

From source file:org.dcm4chee.wizard.validator.CodeValidator.java

License:LGPL

public void validate(Form<?> form) {

    final FormComponent<String> codeValue = components[0];
    final FormComponent<String> codingSchemeDesignator = components[1];
    final FormComponent<String> codingSchemeVersion = components[2];
    final FormComponent<String> codeMeaning = components[3];

    ValidationError validationError = new ValidationError();
    validationError.addKey("CodeValidator.invalid");

    if (!codeValue.getInput().isEmpty()) {
        if (codingSchemeDesignator.getInput().isEmpty())
            codingSchemeDesignator.error(validationError);
        if (codeMeaning.getInput().isEmpty())
            codeMeaning.error(validationError);
        return;/*from   ww  w.  j  av  a  2  s . c om*/
    }
    if (!codingSchemeDesignator.getInput().isEmpty()) {
        if (codeValue.getInput().isEmpty())
            codeValue.error(validationError);
        if (codeMeaning.getInput().isEmpty())
            codeMeaning.error(validationError);
        return;
    }
    if (!codeMeaning.getInput().isEmpty()) {
        if (codeValue.getInput().isEmpty())
            codeValue.error(validationError);
        if (codingSchemeDesignator.getInput().isEmpty())
            codingSchemeDesignator.error(validationError);
        return;
    }
    if (!codingSchemeVersion.getInput().isEmpty()) {
        if (codeValue.getInput().isEmpty())
            codeValue.error(validationError);
        if (codingSchemeDesignator.getInput().isEmpty())
            codingSchemeDesignator.error(validationError);
        if (codeMeaning.getInput().isEmpty())
            codeMeaning.error(validationError);
        return;
    }
}

From source file:org.geoserver.web.data.store.StoreNameValidator.java

License:Open Source License

/**
 * Performs the cross validation between the selected workspace and the assigned store name
 * <p>//from   w w  w.j a  v  a2 s. c  o m
 * If there's already a {@link StoreInfo} in the selected workspace with the same name than the
 * choosed one the store name form component is set with a proper {@link IValidationError error
 * message}
 * </p>
 * 
 * @see IFormValidator#validate(Form)
 */
public void validate(final Form form) {
    final FormComponent[] components = getDependentFormComponents();
    final FormComponent wsComponent = components[0];
    final FormComponent nameComponent = components[1];

    WorkspaceInfo workspace = (WorkspaceInfo) wsComponent.getConvertedInput();
    String name = (String) nameComponent.getConvertedInput();

    if (name == null) {
        if (required) {
            ValidationError error = new ValidationError();
            error.addMessageKey("StoreNameValidator.storeNameRequired");
            nameComponent.error((IValidationError) error);
        }
        return;
    }

    Catalog catalog = GeoServerApplication.get().getCatalog();

    final StoreInfo existing = catalog.getStoreByName(workspace, name, StoreInfo.class);
    if (existing != null) {
        final String existingId = existing.getId();
        if (!existingId.equals(edittingStoreId)) {
            ValidationError error = new ValidationError();
            error.addMessageKey("StoreNameValidator.storeExistsInWorkspace");
            error.setVariable("workspace", workspace.getName());
            error.setVariable("storeName", name);
            nameComponent.error((IValidationError) error);
        }
    }
}

From source file:org.openengsb.ui.common.editor.ServiceEditorPanel.java

License:Apache License

/**
 * attach a ServiceValidator to the given form. This formValidator is meant to validate the fields in context to
 * each other. This validation is only done on submit.
 *//*w  ww. j a  v  a  2  s  . com*/
public void attachFormValidator(final Form<?> form, final FormValidator validator) {
    form.add(new AbstractFormValidator() {

        @Override
        public void validate(Form<?> form) {
            Map<String, FormComponent<?>> loadFormComponents = loadFormComponents(form);
            Map<String, String> toValidate = new HashMap<String, String>();
            for (Map.Entry<String, FormComponent<?>> entry : loadFormComponents.entrySet()) {
                toValidate.put(entry.getKey(), entry.getValue().getValue());
            }
            try {
                validator.validate(toValidate);
            } catch (ConnectorValidationFailedException e) {
                Map<String, String> attributeErrorMessages = e.getErrorMessages();
                for (Map.Entry<String, String> entry : attributeErrorMessages.entrySet()) {
                    FormComponent<?> fc = loadFormComponents.get(entry.getKey());
                    fc.error((IValidationError) new ValidationError().setMessage(entry.getValue()));
                }
            }

        }

        @Override
        public FormComponent<?>[] getDependentFormComponents() {
            Collection<FormComponent<?>> formComponents = loadFormComponents(form).values();
            return formComponents.toArray(new FormComponent<?>[formComponents.size()]);
        }

        private Map<String, FormComponent<?>> loadFormComponents(final Form<?> form) {
            Map<String, FormComponent<?>> formComponents = new HashMap<String, FormComponent<?>>();
            if (validator != null) {
                for (String attribute : validator.fieldsToValidate()) {
                    Component component = form.get("attributesPanel:fields:" + attribute + ":row:field");
                    if (component instanceof FormComponent<?>) {
                        formComponents.put(attribute, (FormComponent<?>) component);
                    }
                }
            }
            return formComponents;
        }
    });
}