Example usage for org.apache.wicket.validation.validator StringValidator exactLength

List of usage examples for org.apache.wicket.validation.validator StringValidator exactLength

Introduction

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

Prototype

public static StringValidator exactLength(int length) 

Source Link

Usage

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  w w  . ja  v  a 2 s .co  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  .  ja  va 2s  .  c  om*/
@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:org.wicketopia.builder.feature.validator.LengthFeature.java

License:Apache License

@Override
protected IValidator<?> createValidator() {
    if (max != Integer.MAX_VALUE && min != Integer.MIN_VALUE) {
        if (max == min) {
            return StringValidator.exactLength(min);
        } else {/*from   w ww . j  a v a2s  .c  o m*/
            return StringValidator.lengthBetween(min, max);
        }
    } else if (max != Integer.MAX_VALUE) {
        return StringValidator.maximumLength(max);
    } else {
        return StringValidator.minimumLength(min);
    }
}