Example usage for org.apache.wicket.validation.validator RangeValidator RangeValidator

List of usage examples for org.apache.wicket.validation.validator RangeValidator RangeValidator

Introduction

In this page you can find the example usage for org.apache.wicket.validation.validator RangeValidator RangeValidator.

Prototype

public RangeValidator(Z minimum, Z maximum) 

Source Link

Document

Constructor that sets the minimum and maximum values.

Usage

From source file:au.org.theark.core.web.component.customfieldcategory.form.DetailForm.java

License:Open Source License

protected void attachValidators() {
    categoryNameTxtFld.setRequired(true);
    categoryNameTxtFld.add(new PatternValidator("[a-zA-Z0-9_-]+"));
    categoryNameTxtFld//from  w ww.  j ava 2 s .c om
            .add(StringValidator.maximumLength(au.org.theark.core.Constants.GENERAL_FIELD_NAME_MAX_LENGTH_50));

    categoryDescriptionTxtAreaFld.add(StringValidator
            .maximumLength(au.org.theark.core.Constants.GENERAL_FIELD_DESCRIPTIVE_MAX_LENGTH_255));
    customFieldTypeDdc.setRequired(true);
    categoryOrderNoTxtFld.setRequired(true);
    categoryOrderNoTxtFld.add(new RangeValidator<Long>(
            new Long(au.org.theark.core.Constants.GENERAL_FIELD_WHOLE_NUMBER_MIN_QUANTITY_1),
            new Long(au.org.theark.core.Constants.GENERAL_FIELD_WHOLE_NUMBER_MAX_QUANTITY_100)));

}

From source file:au.org.theark.study.web.component.managestudy.form.DetailForm.java

License:Open Source License

@Override
protected void attachValidators() {
    studyNameTxtFld.setRequired(true).setLabel(
            new StringResourceModel("error.study.name.required", this, new Model<String>("Study Name")));
    // TODO Have to stop the validator posting the content with the error message
    studyDescriptionTxtArea.add(StringValidator.lengthBetween(1, 255)).setLabel(new StringResourceModel(
            "study.description.length.exceeded", this, new Model<String>("Study Synopsis")));
    studyStatusDpChoices.setRequired(true).setLabel(
            new StringResourceModel("error.study.status.required", this, new Model<String>("Status")));

    // Max dateOfApplicationDp can be only today
    dateOfApplicationDp.add(DateValidator.maximum(new Date()))
            .setLabel(new StringResourceModel("error.study.doa.max.range", this, null));

    // TODO: Write CustomValidator to handle numeric validation
    // Estimated Year of completion a numeric year field, greater than dateOfApplicationDp
    // estYearOfCompletionTxtFld.add(new PatternValidator("^\\d{4}$")).setLabel(new StringResourceModel("error.study.yearOfCompletion", this, new
    // Model<String>("Estimated Year of Completion")));

    chiefInvestigatorTxtFld.setRequired(true).setLabel(
            new StringResourceModel("error.study.chief", this, new Model<String>("Chief Investigator")));
    chiefInvestigatorTxtFld.add(StringValidator.lengthBetween(3, 50));

    coInvestigatorTxtFld.add(StringValidator.lengthBetween(3, 50)).setLabel(
            new StringResourceModel("error.study.co.investigator", this, new Model<String>("Co Investigator")));
    // selectedApplicationsLmc.setRequired(true).setLabel( new StringResourceModel("error.study.selected.app", this, null));
    subjectUidStartTxtFld.add(new RangeValidator<Integer>(1, Integer.MAX_VALUE))
            .setLabel(new StringResourceModel("error.study.subject.key.prefix", this, null));
    // file image validator, checking size, type etc
    fileUploadField.add(new StudyLogoValidator());

    // Make parentStudy drop-down required for Study Administrators and study in context
    Subject currentUser = SecurityUtils.getSubject();
    Long studyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    if (studyId != null) {
        try {/*from  ww  w. j av  a  2 s .co m*/
            if (!iArkCommonService.isSuperAdministrator(currentUser.getPrincipal().toString())) {
                parentStudyDdc.setRequired(true).setLabel(new StringResourceModel("study.parentStudy.required",
                        this, new Model<String>("Parent Study")));
            }
        } catch (EntityNotFoundException e) {
            log.error(e.getMessage());
        }
    }

}

From source file:au.org.theark.study.web.component.phone.form.SearchForm.java

License:Open Source License

protected void attachValidators() {
    phoneIdTxtFld.add(new RangeValidator<Long>(new Long(0), Long.MAX_VALUE));
    areaCodeTxtFld.add(StringValidator.maximumLength(10));
}

From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.HeaderConfigUI.java

License:Apache License

private TextField<Integer> getSizeTextField() {
    TextField<Integer> textField = new FeedbackTextField<Integer>("size");

    textField.setRequired(true);//from   w  w w . j  a v a2s .co  m
    textField.add(new RangeValidator<Integer>(1, 255));
    textField.setLabel(labelSize);
    textField.setOutputMarkupId(true);
    textField.setOutputMarkupPlaceholderTag(true);

    return textField;
}

From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java

License:Apache License

private TextField<Integer> getMessageIdTextField() {

    TextField<Integer> textField = new FeedbackTextField<Integer>("messageId");
    textField.setRequired(true);/* w  w w  . j a  va2 s. c o  m*/

    CompoundValidator<Integer> validator = new CompoundValidator<Integer>();
    validator.add(new RangeValidator<Integer>(0, 65535));
    validator.add(new UniqueMessageIdValidator());
    textField.add(validator);
    textField.setOutputMarkupId(true);

    textField.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            // The id is the key for the message map, so we have to replace it here
            getConfig().messages.remove(currentMessageId);
            getConfig().addMessageConfig(currentMessage);
            currentMessageId = currentMessage.getMessageId();
            target.add(currentMessageIdDropdown);

            // Clear feedback messages
            target.addChildren(getPage(), FeedbackPanel.class);
            target.add(getComponent());
        }

        @Override
        protected void onError(AjaxRequestTarget target, RuntimeException e) {
            target.addChildren(getPage(), FeedbackPanel.class);
            target.add(getComponent());
        }
    });

    return textField;
}

From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java

License:Apache License

private TextField<Integer> getIdTextField() {

    TextField<Integer> textField = new FeedbackTextField<Integer>("id");
    textField.setRequired(true);/*  w w  w.  j av  a  2  s.  c  om*/

    CompoundValidator<Integer> validator = new CompoundValidator<Integer>();
    validator.add(new UniqueListItemValidator<Integer>(textField).setMessageKey("id.UniqueValueValidator"));
    validator.add(new RangeValidator<Integer>(1, 254));
    textField.add(validator);

    textField.setLabel(labelId);
    textField.setOutputMarkupId(true);

    return textField;
}

From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java

License:Apache License

private TextField<Integer> getSizeTextField() {

    TextField<Integer> textField = new FeedbackTextField<Integer>("size");

    textField.setRequired(true);//from  w  w w. ja  v  a2 s  .  c  o  m
    textField.add(new RangeValidator<Integer>(1, 1000));

    textField.setLabel(labelSize);

    textField.setOutputMarkupId(true);

    // When the size is changed, the offsets are recalculated and displayed
    textField.add(new OnChangeAjaxBehavior() {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            updateOffsets(target);
        }
    });

    return textField;
}

From source file:com.cubeia.backoffice.web.wallet.EditCurrencies.java

License:Open Source License

/**
* Constructor that is invoked when page is invoked without a session.
*
*///from w ww  .j  ava 2 s  .c o m
@SuppressWarnings("serial")
public EditCurrencies() {
    add(new FeedbackPanel("feedback", new ComponentFeedbackMessageFilter(EditCurrencies.this)));

    IModel<List<Currency>> currencyModel = new LoadableDetachableModel<List<Currency>>() {
        @Override
        protected List<Currency> load() {
            CurrencyListResult supportedCurrencies = walletService.getSupportedCurrencies();

            if (supportedCurrencies == null) {
                return Collections.<Currency>emptyList();
            }

            ArrayList<Currency> curs = new ArrayList<Currency>(supportedCurrencies.getCurrencies());
            log.debug("got currencies: {}", curs);
            Collections.sort(curs, new Comparator<Currency>() {
                @Override
                public int compare(Currency o1, Currency o2) {
                    return o1.getCode().compareTo(o2.getCode());
                }
            });
            return curs;
        }
    };

    add(new ListView<Currency>("currencies", currencyModel) {
        @Override
        protected void populateItem(ListItem<Currency> item) {
            final Currency c = item.getModelObject();
            item.add(new Label("code", Model.of(c.getCode())));
            item.add(new Label("digits", Model.of(c.getFractionalDigits())));

            item.add(new Link<String>("removeLink") {
                @Override
                public void onClick() {
                    log.debug("removing currency: {}", c);
                    walletService.removeCurrency(c.getCode());
                }
            }.add(new ConfirmOnclickAttributeModifier("Really remove this currency?")));
        }
    });

    final CompoundPropertyModel<Currency> newCurrencyModel = new CompoundPropertyModel<Currency>(
            new Currency(null, 2));

    Form<Currency> addForm = new Form<Currency>("addForm", newCurrencyModel) {
        @Override
        protected void onSubmit() {
            Currency cur = getModelObject();
            log.debug("submit: {}", cur);

            try {
                walletService.addCurrency(cur);
            } catch (Exception e) {
                error("Error creating currency: " + e.getMessage());
                return;
            }

            info("Added currency " + cur.getCode() + " with " + cur.getFractionalDigits()
                    + " fractional digits");
            newCurrencyModel.setObject(new Currency(null, 2));
        }
    };

    addForm.add(new RequiredTextField<String>("code", newCurrencyModel.<String>bind("code"))
            .add(StringValidator.exactLength(3)));
    addForm.add(new RequiredTextField<Integer>("digits", newCurrencyModel.<Integer>bind("fractionalDigits"))
            .add(new RangeValidator<Integer>(0, 8)));
    addForm.add(new FeedbackPanel("feedback", new ContainerFeedbackMessageFilter(addForm)));
    addForm.add(new WebMarkupContainer("submitButton")
            .add(new ConfirmOnclickAttributeModifier("Are you sure you want to add this currency?")));
    add(addForm);
}

From source file:com.cubeia.games.poker.admin.wicket.pages.wallet.EditCurrencies.java

License:Open Source License

/**
* Constructor that is invoked when page is invoked without a session.
*
*//*from w  w w .j  a  va 2 s . co  m*/
@SuppressWarnings("serial")
public EditCurrencies(PageParameters parameters) {
    super(parameters);
    add(new FeedbackPanel("feedback", new ComponentFeedbackMessageFilter(EditCurrencies.this)));

    IModel<List<Currency>> currencyModel = new LoadableDetachableModel<List<Currency>>() {
        @Override
        protected List<Currency> load() {
            CurrencyListResult supportedCurrencies = walletService.getSupportedCurrencies();

            if (supportedCurrencies == null) {
                return Collections.<Currency>emptyList();
            }

            ArrayList<Currency> curs = new ArrayList<Currency>(supportedCurrencies.getCurrencies());
            log.debug("got currencies: {}", curs);
            Collections.sort(curs, new Comparator<Currency>() {
                @Override
                public int compare(Currency o1, Currency o2) {
                    return o1.getCode().compareTo(o2.getCode());
                }
            });
            return curs;
        }
    };

    add(new ListView<Currency>("currencies", currencyModel) {
        @Override
        protected void populateItem(ListItem<Currency> item) {
            final Currency c = item.getModelObject();
            item.add(new Label("code", Model.of(c.getCode())));
            item.add(new Label("digits", Model.of(c.getFractionalDigits())));

            item.add(new Link<String>("removeLink") {
                @Override
                public void onClick() {
                    log.debug("removing currency: {}", c);
                    walletService.removeCurrency(c.getCode());
                }
            }.add(new ConfirmOnclickAttributeModifier("Really remove this currency?")));
        }
    });

    final CompoundPropertyModel<Currency> newCurrencyModel = new CompoundPropertyModel<Currency>(
            new Currency(null, 2));

    Form<Currency> addForm = new Form<Currency>("addForm", newCurrencyModel) {
        @Override
        protected void onSubmit() {
            Currency cur = getModelObject();
            log.debug("submit: {}", cur);

            try {
                walletService.addCurrency(cur);
            } catch (Exception e) {
                error("Error creating currency: " + e.getMessage());
                return;
            }

            info("Added currency " + cur.getCode() + " with " + cur.getFractionalDigits()
                    + " fractional digits");
            newCurrencyModel.setObject(new Currency(null, 2));
        }
    };

    addForm.add(new RequiredTextField<String>("code", newCurrencyModel.<String>bind("code"))
            .add(StringValidator.exactLength(3)));
    addForm.add(new RequiredTextField<Integer>("digits", newCurrencyModel.<Integer>bind("fractionalDigits"))
            .add(new RangeValidator<Integer>(0, 8)));
    addForm.add(new FeedbackPanel("feedback", new ContainerFeedbackMessageFilter(addForm)));
    addForm.add(new WebMarkupContainer("submitButton")
            .add(new ConfirmOnclickAttributeModifier("Are you sure you want to add this currency?")));
    add(addForm);
}

From source file:com.evolveum.midpoint.web.component.data.TableConfigurationPanel.java

License:Apache License

private void initPopoverLayout() {
    WebMarkupContainer popover = new WebMarkupContainer(ID_POPOVER);
    popover.setOutputMarkupId(true);//from ww w  .ja  v a2  s.co  m
    add(popover);

    Form form = new Form(ID_FORM);
    popover.add(form);

    AjaxSubmitButton button = new AjaxSubmitButton(ID_BUTTON) {

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(TableConfigurationPanel.this
                    .get(createComponentPath(ID_POPOVER, ID_FORM, "inputFeedback")));
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            pageSizeChanged(target);
        }
    };
    form.add(button);

    TextField input = new TextField(ID_INPUT, createInputModel());
    input.add(new RangeValidator(5, 100));
    input.setLabel(createStringResource("PageSizePopover.title"));
    input.add(new SearchFormEnterBehavior(button));
    input.setType(Integer.class);
    input.setOutputMarkupId(true);

    FeedbackPanel feedback = new FeedbackPanel("inputFeedback", new ComponentFeedbackMessageFilter(input));
    feedback.setOutputMarkupId(true);
    form.add(feedback);
    form.add(input);
}