Search in sources :

Example 1 with IValidator

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

the class WizardStep method createObjectClassValidator.

protected IValidator<String> createObjectClassValidator(final IModel<List<QName>> model) {
    return new IValidator<String>() {

        @Override
        public void validate(IValidatable<String> validated) {
            String value = validated.getValue();
            List<QName> list = model.getObject();
            List<String> stringList = new ArrayList<>();
            for (QName q : list) {
                stringList.add(q.getLocalPart());
            }
            if (!stringList.contains(value)) {
                error(createStringResource("SchemaHandlingStep.message.validationError", value).getString());
                AjaxRequestTarget target = getRequestCycle().find(AjaxRequestTarget.class);
                target.add(getPageBase().getFeedbackPanel());
            }
        }
    };
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IValidator(org.apache.wicket.validation.IValidator) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) IValidatable(org.apache.wicket.validation.IValidatable)

Example 2 with IValidator

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

the class PageReport method createFullXmlValidator.

private IValidator<String> createFullXmlValidator() {
    return new IValidator<String>() {

        @Override
        public void validate(IValidatable<String> validatable) {
            String value = validatable.getValue();
            OperationResult result = new OperationResult(OPERATION_VALIDATE_REPORT);
            Holder<PrismObject<ReportType>> reportHolder = new Holder<>(null);
            OpResult opResult = null;
            try {
                validateObject(value, reportHolder, PrismContext.LANG_XML, true, result);
                if (!result.isAcceptable()) {
                    result.recordFatalError("Could not validate object", result.getCause());
                    opResult = OpResult.getOpResult((PageBase) getPage(), result);
                    validatable.error(new RawValidationError(opResult));
                }
            } catch (Exception e) {
                LOGGER.error("Validation problem occured." + e.getMessage());
                result.recordFatalError("Could not validate object.", e);
                try {
                    opResult = OpResult.getOpResult((PageBase) getPage(), result);
                    validatable.error(new RawValidationError(opResult));
                } catch (Exception ex) {
                    error(ex);
                }
            }
        }
    };
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) IValidator(org.apache.wicket.validation.IValidator) Holder(com.evolveum.midpoint.util.Holder) OpResult(com.evolveum.midpoint.gui.api.component.result.OpResult) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) RawValidationError(org.apache.wicket.validation.RawValidationError) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RestartResponseException(org.apache.wicket.RestartResponseException) IValidatable(org.apache.wicket.validation.IValidatable)

Example 3 with IValidator

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

the class PageAccounts method createObjectClassValidator.

private IValidator<String> createObjectClassValidator() {
    return new IValidator<String>() {

        @Override
        public void validate(IValidatable<String> validatable) {
            String value = validatable.getValue();
            AccountDetailsSearchDto dto = searchModel.getObject();
            List<QName> accountObjectClassList = dto.getObjectClassList();
            List<String> accountObjectClassListString = new ArrayList<>();
            for (QName objectClass : accountObjectClassList) {
                accountObjectClassListString.add(objectClass.getLocalPart());
            }
            if (!accountObjectClassListString.contains(value)) {
                error(createStringResource("PageAccounts.message.validationError", value).getString());
            }
        }
    };
}
Also used : AccountDetailsSearchDto(com.evolveum.midpoint.web.page.admin.configuration.dto.AccountDetailsSearchDto) IValidator(org.apache.wicket.validation.IValidator) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) IValidatable(org.apache.wicket.validation.IValidatable)

Example 4 with IValidator

use of org.apache.wicket.validation.IValidator 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)

Aggregations

IValidatable (org.apache.wicket.validation.IValidatable)4 IValidator (org.apache.wicket.validation.IValidator)4 ArrayList (java.util.ArrayList)2 QName (javax.xml.namespace.QName)2 OpResult (com.evolveum.midpoint.gui.api.component.result.OpResult)1 PageBase (com.evolveum.midpoint.gui.api.page.PageBase)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 Holder (com.evolveum.midpoint.util.Holder)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 TextPanel (com.evolveum.midpoint.web.component.input.TextPanel)1 AccountDetailsSearchDto (com.evolveum.midpoint.web.page.admin.configuration.dto.AccountDetailsSearchDto)1 RestartResponseException (org.apache.wicket.RestartResponseException)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 AttributeAppender (org.apache.wicket.behavior.AttributeAppender)1 FormComponent (org.apache.wicket.markup.html.form.FormComponent)1 RawValidationError (org.apache.wicket.validation.RawValidationError)1 ValidationError (org.apache.wicket.validation.ValidationError)1