Search in sources :

Example 1 with ValidationError

use of org.apache.wicket.validation.ValidationError in project ocvn by devgateway.

the class EarlierThanDateValidator method validate.

@Override
public void validate(final IValidatable<Date> validatable) {
    if (highDate == null) {
        return;
    }
    if (validatable.getValue() != null && highDate.before(validatable.getValue())) {
        ValidationError error = new ValidationError(this);
        error.setVariable("highDate", highDate);
        validatable.error(error);
    }
}
Also used : ValidationError(org.apache.wicket.validation.ValidationError)

Example 2 with ValidationError

use of org.apache.wicket.validation.ValidationError in project ocvn by devgateway.

the class VietnamImportPage method addImportButton.

protected void addImportButton() {
    importButton = new LaddaAjaxButton("import", Type.Danger) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            send(getPage(), Broadcast.BREADTH, new EditingDisabledEvent());
            logText.getSelfUpdatingBehavior().restart(target);
            importContainer.setVisibilityAllowed(true);
            target.add(importContainer);
            target.add(form);
            try {
                vnExcelImportService.importAllSheets(importForm.getModelObject().getFileTypes(), importForm.getModelObject().getSourceFiles().getPrototypeDatabaseFile().isEmpty() ? null : importForm.getModelObject().getSourceFiles().getPrototypeDatabaseFile().iterator().next().getContent().getBytes(), importForm.getModelObject().getSourceFiles().getLocationsFile().isEmpty() ? null : importForm.getModelObject().getSourceFiles().getLocationsFile().iterator().next().getContent().getBytes(), importForm.getModelObject().getSourceFiles().getPublicInstitutionsSuppliersFile().isEmpty() ? null : importForm.getModelObject().getSourceFiles().getPublicInstitutionsSuppliersFile().iterator().next().getContent().getBytes(), importForm.getModelObject().getSourceFiles().getCityDepartmentGroupFile().isEmpty() ? null : importForm.getModelObject().getSourceFiles().getCityDepartmentGroupFile().iterator().next().getContent().getBytes(), importForm.getModelObject().getDropData(), importForm.getModelObject().getValidateData(), importForm.getModelObject().getFlagData());
            } catch (Exception e) {
                logger.error(e);
                e.printStackTrace();
            } finally {
                target.add(logText);
                target.add(feedbackPanel);
                this.setEnabled(false);
                target.add(this);
            }
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form<?> form) {
            ValidationError error = new ValidationError();
            error.addKey("formHasErrors");
            error(error);
            target.add(form);
            target.add(feedbackPanel);
        }
    };
    importButton.setLabel(new ResourceModel("startImportProcess"));
    importButton.setIconType(FontAwesomeIconType.hourglass_start);
    importForm.add(importButton);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) LaddaAjaxButton(de.agilecoders.wicket.extensions.markup.html.bootstrap.ladda.LaddaAjaxButton) ResourceModel(org.apache.wicket.model.ResourceModel) EditingDisabledEvent(org.devgateway.toolkit.forms.wicket.events.EditingDisabledEvent) ValidationError(org.apache.wicket.validation.ValidationError)

Example 3 with ValidationError

use of org.apache.wicket.validation.ValidationError in project midpoint by Evolveum.

the class NotNullValidator method validate.

@Override
public void validate(IValidatable<T> validatable) {
    if (validatable.getValue() == null) {
        ValidationError err = new ValidationError();
        err.addKey(key);
        validatable.error(err);
    }
}
Also used : ValidationError(org.apache.wicket.validation.ValidationError)

Example 4 with ValidationError

use of org.apache.wicket.validation.ValidationError in project midpoint by Evolveum.

the class JasperReportConfigurationPanel method createTextPanel.

@SuppressWarnings({ "rawtypes", "unchecked" })
private <J> Component createTextPanel(String componentId, final IModel<J> model, String expression, final Boolean mandatory) {
    TextPanel<String> textPanel = new TextPanel<String>(componentId, new PropertyModel<String>(model, expression));
    FormComponent input = textPanel.getBaseFormComponent();
    input.add(new AttributeAppender("style", "width: 100%"));
    input.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    input.add(new IValidator() {

        private static final long serialVersionUID = 1L;

        @Override
        public void validate(IValidatable validatable) {
            if (!mandatory) {
                return;
            }
            if (validatable.getValue() == null) {
                validatable.error(new ValidationError("JasperReportConfigurationPanel.errormsg"));
            }
        }
    });
    return textPanel;
}
Also used : FormComponent(org.apache.wicket.markup.html.form.FormComponent) IValidator(org.apache.wicket.validation.IValidator) TextPanel(com.evolveum.midpoint.web.component.input.TextPanel) ValidationError(org.apache.wicket.validation.ValidationError) AttributeAppender(org.apache.wicket.behavior.AttributeAppender) IValidatable(org.apache.wicket.validation.IValidatable)

Example 5 with ValidationError

use of org.apache.wicket.validation.ValidationError in project ocvn by devgateway.

the class EarlierThanDateFieldValidator method validate.

@Override
public void validate(final IValidatable<Date> validatable) {
    highDate.getField().validate();
    if (!highDate.getField().isValid()) {
        return;
    }
    Date endDate = (Date) highDate.getField().getConvertedInput();
    if (endDate != null && validatable.getValue() != null && endDate.before(validatable.getValue())) {
        ValidationError error = new ValidationError(this);
        error.setVariable("highDateName", new StringResourceModel(highDate.getLabelKey(), highDate.getParent(), null).getString());
        validatable.error(error);
    }
}
Also used : ValidationError(org.apache.wicket.validation.ValidationError) StringResourceModel(org.apache.wicket.model.StringResourceModel) Date(java.util.Date)

Aggregations

ValidationError (org.apache.wicket.validation.ValidationError)6 TextPanel (com.evolveum.midpoint.web.component.input.TextPanel)1 LaddaAjaxButton (de.agilecoders.wicket.extensions.markup.html.bootstrap.ladda.LaddaAjaxButton)1 Date (java.util.Date)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 AttributeAppender (org.apache.wicket.behavior.AttributeAppender)1 FormComponent (org.apache.wicket.markup.html.form.FormComponent)1 ResourceModel (org.apache.wicket.model.ResourceModel)1 StringResourceModel (org.apache.wicket.model.StringResourceModel)1 IValidatable (org.apache.wicket.validation.IValidatable)1 IValidator (org.apache.wicket.validation.IValidator)1 EditingDisabledEvent (org.devgateway.toolkit.forms.wicket.events.EditingDisabledEvent)1