Search in sources :

Example 1 with IValidatable

use of org.apache.wicket.validation.IValidatable 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 2 with IValidatable

use of org.apache.wicket.validation.IValidatable 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 3 with IValidatable

use of org.apache.wicket.validation.IValidatable 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).get();
                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 4 with IValidatable

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

use of org.apache.wicket.validation.IValidatable in project openmeetings by apache.

the class ConfigForm method onInitialize.

@Override
protected void onInitialize() {
    super.onInitialize();
    add(new DropDownChoice<>("type", Arrays.asList(Type.values()), new IChoiceRenderer<Type>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getIdValue(Type rt, int index) {
            return rt.name();
        }

        @Override
        public Object getDisplayValue(Type rt) {
            return rt.name();
        }

        @Override
        public Type getObject(String id, IModel<? extends List<? extends Type>> choices) {
            for (Type rt : choices.getObject()) {
                if (rt.name().equals(id)) {
                    return rt;
                }
            }
            return null;
        }
    }).setLabel(Model.of(getString("45"))).add(new AjaxFormComponentUpdatingBehavior("change") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            update(target);
        }
    }));
    add(new RequiredTextField<String>("key").setLabel(Model.of(getString("265"))).add(new IValidator<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public void validate(IValidatable<String> validatable) {
            Configuration c = cfgDao.forceGet(validatable.getValue());
            if (c != null && !c.isDeleted() && !c.getId().equals(ConfigForm.this.getModelObject().getId())) {
                validatable.error(new ValidationError(getString("error.cfg.exist")));
            }
        }
    }));
    add(valueS.setLabel(Model.of(getString("271"))).setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true));
    add(valueN.setLabel(Model.of(getString("271"))).setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true));
    add(valueB.setLabel(Model.of(getString("271"))).setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true));
}
Also used : IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) IModel(org.apache.wicket.model.IModel) Configuration(org.apache.openmeetings.db.entity.basic.Configuration) IValidatable(org.apache.wicket.validation.IValidatable) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Type(org.apache.openmeetings.db.entity.basic.Configuration.Type) IValidator(org.apache.wicket.validation.IValidator) List(java.util.List) ValidationError(org.apache.wicket.validation.ValidationError)

Aggregations

IValidatable (org.apache.wicket.validation.IValidatable)5 IValidator (org.apache.wicket.validation.IValidator)5 ArrayList (java.util.ArrayList)2 QName (javax.xml.namespace.QName)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 ValidationError (org.apache.wicket.validation.ValidationError)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 List (java.util.List)1 Configuration (org.apache.openmeetings.db.entity.basic.Configuration)1 Type (org.apache.openmeetings.db.entity.basic.Configuration.Type)1 RestartResponseException (org.apache.wicket.RestartResponseException)1 AjaxFormComponentUpdatingBehavior (org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior)1 AttributeAppender (org.apache.wicket.behavior.AttributeAppender)1