Example usage for org.apache.wicket.validation IValidatable isValid

List of usage examples for org.apache.wicket.validation IValidatable isValid

Introduction

In this page you can find the example usage for org.apache.wicket.validation IValidatable isValid.

Prototype

boolean isValid();

Source Link

Document

Queries the current state of this IValidatable instance.

Usage

From source file:com.github.cage.cage_e03_wicket.HomePage.java

License:Apache License

public HomePage() {
    super(new CompoundPropertyModel<Token>(new Token()));
    add(new WebMarkupContainer("goodResult") {
        private static final long serialVersionUID = -5279236538017405828L;

        @Override//from w  w w.j a  v a 2  s .  c o m
        protected void onConfigure() {
            super.onConfigure();

            final Token token = HomePage.this.getToken();

            setVisible(token.showGoodResult);
            token.showGoodResult = false;
        }
    });
    add(new WebMarkupContainer("badResult") {
        private static final long serialVersionUID = -6479933043124566245L;

        @Override
        protected void onConfigure() {
            super.onConfigure();

            final Token token = HomePage.this.getToken();

            setVisible(token.showBadResult);
            token.showBadResult = false;
        }
    });

    add(new Form<Token>("form") {
        private static final long serialVersionUID = -2783383042739263677L;

        @Override
        protected void onInitialize() {
            super.onInitialize();
            add(new RequiredTextField<String>("captcha") {
                private static final long serialVersionUID = 8416111619173955610L;

                @Override
                protected void onComponentTag(ComponentTag tag) {
                    super.onComponentTag(tag);
                    tag.put("value", "");
                };
            }.add(new StringValidator() {
                private static final long serialVersionUID = 3888825725858419028L;

                @Override
                public void validate(IValidatable<String> validatable) {
                    super.validate(validatable);
                    if (!validatable.isValid())
                        return;

                    final Token token = HomePage.this.getToken();

                    if (token.token == null || !token.token.equals(validatable.getValue())) {
                        LOGGER.error("There was no generated token, or it didn't match the user given one.");
                        validatable.error(decorate(new ValidationError(this), validatable));
                    }
                }
            }));
        }

        @Override
        protected void onSubmit() {
            super.onSubmit();
            onPost(true);
        }

        @Override
        protected void onError() {
            super.onError();
            onPost(false);
        }

        protected void onPost(boolean good) {
            final Token token = HomePage.this.getToken();

            token.showGoodResult = good;
            token.showBadResult = !good;
        }
    });

    add(new Image("captchaImage", new DynamicImageResource(cage.getFormat()) {
        private static final long serialVersionUID = -1475355045487272906L;

        @Override
        protected void configureResponse(ResourceResponse response, Attributes attributes) {
            super.configureResponse(response, attributes);
            final Token token = HomePage.this.getToken();

            LOGGER.info("Token: {}.", token);

            if (token.token == null || token.tokenUsed) {
                LOGGER.error("Requested captcha without token.");
                response.setError(HttpServletResponse.SC_NOT_FOUND, "Captcha not found.");
            }
            token.tokenUsed = true;

            response.disableCaching();
        }

        @Override
        protected byte[] getImageData(Attributes attributes) {
            final Token token = HomePage.this.getToken();

            return cage.draw(token.token);
        }
    }));
}

From source file:com.myamamoto.wicket.misc.validator.JancodeValidator.java

License:Apache License

@Override
protected void onValidate(IValidatable<String> validatable) {
    this.regexValidator.validate(validatable);
    if (!validatable.isValid()) {
        return;/*w ww .  ja v a 2 s . co  m*/
    }
    String jancode = validatable.getValue();
    if (!this.isValidJancode(jancode)) {
        super.error(validatable);
    }
}

From source file:eu.clarin.cmdi.virtualcollectionregistry.service.impl.ReferenceValidator.java

License:Open Source License

@Override
public void validate(IValidatable<String> validatable) {
    // first check if it is a valid handle
    if (!HANDLE_PATTERN.matcher(validatable.getValue()).matches()) {
        // check if it is a valid URL
        urlValidator.validate(validatable);
        if (!validatable.isValid()) {
            validatable.error(new ValidationError()
                    .setMessage(String.format("'%s' is not a valid handle", validatable.getValue())));
        }//from   w  ww .  ja  va2  s . c  om

        httpResponseValidator.validate(validatable);
    }
}

From source file:eu.clarin.cmdi.virtualcollectionregistry.service.impl.ReferenceValidatorTest.java

License:Open Source License

/**
 * Test of onValidate method, of class ReferenceValidator.
 *//*from w w  w. j av  a  2 s.  c  om*/
@Test
public void testOnValidateUrl() {
    IValidatable<String> validatable = new Validatable<>("http://www.clarin.eu");
    instance.validate(validatable);
    assertTrue(validatable.isValid());
}

From source file:eu.clarin.cmdi.virtualcollectionregistry.service.impl.ReferenceValidatorTest.java

License:Open Source License

/**
 * Test of onValidate method, of class ReferenceValidator.
 *///  w  ww .  j  ava  2  s  . c  o  m
@Test
public void testOnValidateHdl() {
    IValidatable<String> validatable = new Validatable<>("hdl:1234/abcd-EF-5678");
    instance.validate(validatable);
    assertTrue(validatable.isValid());
}

From source file:eu.clarin.cmdi.virtualcollectionregistry.service.impl.ReferenceValidatorTest.java

License:Open Source License

/**
 * Test of onValidate method, of class ReferenceValidator.
 *///  www. j ava 2s.c om
@Test
public void testOnValidateDoi() {
    IValidatable<String> validatable = new Validatable<>("doi:10.1000/182");
    instance.validate(validatable);
    assertTrue(validatable.isValid());
}

From source file:eu.clarin.cmdi.virtualcollectionregistry.service.impl.ReferenceValidatorTest.java

License:Open Source License

/**
 * Test of onValidate method, of class ReferenceValidator.
 *///from ww w.j a  va 2 s . co m
@Test
public void testOnValidateIllegal() {
    IValidatable<String> validatable = new Validatable<>("not a legal URL or handle");
    instance.validate(validatable);
    assertFalse(validatable.isValid());
}

From source file:eu.clarin.cmdi.virtualcollectionregistry.service.impl.ReferenceValidatorTest.java

License:Open Source License

/**
 * Test of onValidate method, of class ReferenceValidator.
 *//*  ww  w . j  a  v a  2  s.  c  om*/
@Test
public void testOnValidateIllegalHdl() {
    IValidatable<String> validatable = new Validatable<>("hdl:12a4/abcd-EF-5678");
    instance.validate(validatable);
    assertFalse(validatable.isValid());
}

From source file:gr.abiss.calipso.wicket.components.validators.ValidationExpressionValidator.java

License:Open Source License

@Override
protected void onValidate(final IValidatable<String> validatable) {
    if (!this.skipValidation) {
        super.onValidate(new IValidatable<String>() {

            @Override/* w w  w.  j a v  a2 s. co  m*/
            public String getValue() {
                // TODO Auto-generated method stub
                return validatable.getValue().replaceAll("\\s", "");
            }

            @Override
            public void error(IValidationError error) {
                validatable.error(error);
            }

            @Override
            public boolean isValid() {
                // TODO Auto-generated method stub
                return validatable.isValid();
            }

            @Override
            public IModel<String> getModel() {
                // TODO Auto-generated method stub
                return new Model<String>(this.getValue());
            }

        });
    }
}

From source file:hsa.awp.admingui.rule.rules.AbstractRulePanel.java

License:Open Source License

/**
 * Creates a new RulePanel./*from  w  w  w  .ja  va  2s .  co  m*/
 *
 * @param id   wicket-id.
 * @param rule rule that is created or edited. The values will be used to fill the rule's input fields with default values.
 */
public AbstractRulePanel(String id, T rule) {

    super(id);

    if (rule == null) {
        throw new IllegalArgumentException("No rule given");
    }

    this.rule = rule;

    feedbackPanel = new FeedbackPanel("feedbackPanel");
    feedbackPanel.setOutputMarkupId(true);
    add(feedbackPanel);

    form = new Form<Object>("rule.form");
    add(form);

    name = new TextField<String>("rule.name", new Model<String>(rule.getName()));
    name.setRequired(true);
    name.add(new StringValidator() {
        /**
         * unique serialization id.
         */
        private static final long serialVersionUID = -3503841430415001646L;

        @Override
        protected void onValidate(IValidatable<String> validatable) {

            if (validatable.getValue() == null || validatable.getValue().equals("")) {
                validatable.error(new IValidationErrorSerializable() {
                    /**
                     * unique serialization id.
                     */
                    private static final long serialVersionUID = 2893129433111740381L;

                    @Override
                    public String getErrorMessage(IErrorMessageSource messageSource) {

                        return "Kein Name ausgewhlt";
                    }
                });
            }

            if (validatable.isValid()
                    && controller.getRuleByNameAndMandator(validatable.getValue(), getSession()) != null) {
                validatable.error(new IValidationErrorSerializable() {
                    /**
                     * unique serialization id.
                     */
                    private static final long serialVersionUID = 4583676857544619819L;

                    @Override
                    public String getErrorMessage(IErrorMessageSource messageSource) {

                        return "Regelname existiert bereits.";
                    }
                });
            }
        }
    });

    form.add(name);

    form.add(new AjaxButton("rule.submit") {
        /**
         * unique serialization id.
         */
        private static final long serialVersionUID = -725179447540520694L;

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {

            target.addComponent(feedbackPanel);
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            target.addComponent(feedbackPanel);

            submitOnClick(target, form);
        }
    });
}