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

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

Introduction

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

Prototype

public static StringValidator lengthBetween(int minimum, int maximum) 

Source Link

Usage

From source file:au.org.theark.report.web.component.dataextraction.form.DetailForm.java

License:Open Source License

@Override
protected void attachValidators() {
    searchNameTxtFld.setRequired(true).setLabel(new StringResourceModel("error.search.name.required",
            searchNameTxtFld, new Model<String>("Search Name")));
    searchNameTxtFld.add(StringValidator.lengthBetween(1, 255)).setLabel(new StringResourceModel(
            "error.search.name.length", searchNameTxtFld, new Model<String>("Search Name")));
}

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 a  v  a2  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.manageuser.form.DetailForm.java

License:Open Source License

@Override
protected void attachValidators() {
    lastNameTxtField.add(StringValidator.lengthBetween(1, 50))
            .setLabel(new StringResourceModel("lastName", this, null));
    lastNameTxtField.setRequired(true);//from   w  ww  . j  a v  a2  s. c o  m

    userNameTxtField.add(StringValidator.lengthBetween(1, 50))
            .setLabel(new StringResourceModel("userName", this, null));
    userNameTxtField.add(EmailAddressValidator.getInstance())
            .setLabel(new StringResourceModel("userName.incorrectPattern", this, null));
    userNameTxtField.setRequired(true).setLabel(new StringResourceModel("userName", this, null));

    firstNameTxtField.setRequired(true).setLabel(new StringResourceModel("firstName", this, null));
    firstNameTxtField.add(StringValidator.lengthBetween(1, 50))
            .setLabel(new StringResourceModel("firstName", this, null));

    emailTxtField.add(StringValidator.lengthBetween(1, 50))
            .setLabel(new StringResourceModel("email", this, null));
    emailTxtField.add(EmailAddressValidator.getInstance())
            .setLabel(new StringResourceModel("email.incorrectpattern", this, null));
    emailTxtField.setRequired(true).setLabel(new StringResourceModel("email", this, null));

    userPasswordField.setRequired(isNew());
    confirmPasswordField.setRequired(isNew());

    // Set the confirm password with a password pattern
    userPasswordField.setLabel(Model.of("Password"));
    userPasswordField.add(new PatternValidator(Constants.PASSWORD_PATTERN));
    confirmPasswordField.setLabel(Model.of("Confirm Password"));
}

From source file:au.org.theark.study.web.component.mydetails.form.MyDetailsForm.java

License:Open Source License

private void attachValidators() {
    userNameTxtField.add(EmailAddressValidator.getInstance())
            .setLabel(new StringResourceModel("userName.incorrect.format", this, null));
    userNameTxtField.setRequired(true).setLabel(new StringResourceModel("userName", this, null));
    userNameTxtField.add(StringValidator.lengthBetween(3, 50))
            .setLabel(new StringResourceModel("userName", this, null));

    firstNameTxtField.setRequired(true).setLabel(new StringResourceModel("firstName", this, null));
    firstNameTxtField.add(StringValidator.lengthBetween(3, 50))
            .setLabel(new StringResourceModel("firstName", this, null));

    emailTxtField.add(EmailAddressValidator.getInstance())
            .setLabel(new StringResourceModel("email.incorrect.format", this, null));
    emailTxtField.setRequired(true).setLabel(new StringResourceModel("email", this, null));

    lastNameTxtField.add(StringValidator.lengthBetween(3, 50))
            .setLabel(new StringResourceModel("lastNameLength", this, null));
    lastNameTxtField.setRequired(true).setLabel(new StringResourceModel("lastName", this, null));

    userPasswordField.setRequired(false);
    confirmPasswordField.setRequired(false);

    userPasswordField.setLabel(Model.of("Password"));
    userPasswordField.add(new PatternValidator(Constants.PASSWORD_PATTERN));
    confirmPasswordField.setLabel(Model.of("Confirm Password"));
}

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

License:Open Source License

@Override
protected void attachValidators() {
    componentNameTxtFld.setRequired(true)
            .setLabel(new StringResourceModel("error.study.component.name.required", componentNameTxtFld,
                    new Model<String>("Study Component Name")));
    componentNameTxtFld.add(StringValidator.lengthBetween(3, 100))
            .setLabel(new StringResourceModel("error.study.component.name.length", componentNameTxtFld,
                    new Model<String>("Study Component Name")));
    componentDescription.add(StringValidator.lengthBetween(5, 500)).setLabel(new StringResourceModel(
            "error.study.component.description.length", this, new Model<String>("Description")));
    keywordTxtArea.add(StringValidator.lengthBetween(1, 255)).setLabel(new StringResourceModel(
            "error.study.component.keywords.length", this, new Model<String>("Keywords")));
}

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

License:Apache License

private TextField<String> getMessageAliasTextField() {

    TextField<String> textField = new FeedbackTextField<String>("messageAlias");
    textField.setRequired(true);//  w ww. j  a  v a 2s . com

    CompoundValidator<String> validator = new CompoundValidator<String>();

    validator.add(new PatternValidator("[A-Za-z0-9_]+"));
    validator.add(StringValidator.lengthBetween(1, 32));
    validator.add(new UniqueMessageAliasValidator());
    textField.add(validator);

    textField.setLabel(labelAlias); // Use the same label as the items
    textField.setOutputMarkupId(true);

    textField.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(currentMessageIdDropdown);
            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<String> getAliasTextField() {
    TextField<String> textField = new FeedbackTextField<String>("alias");

    textField.setRequired(true);/*from   w w  w. jav a  2 s.com*/

    CompoundValidator<String> validator = new CompoundValidator<String>();
    validator.add(new PatternValidator("[A-Za-z0-9_]+"));

    validator.add(StringValidator.lengthBetween(1, 32));

    validator.add(new UniqueListItemValidator<String>(textField).setMessageKey("alias.UniqueValueValidator"));

    validator.add(new NonMatchStringValidator(specialAlias));

    textField.add(validator);
    textField.setLabel(labelAlias);
    textField.setOutputMarkupId(true);
    textField.setOutputMarkupPlaceholderTag(true);

    return textField;
}

From source file:com.example.justaddwater.web.app.ChangePasswordPage.java

License:Apache License

public ChangePasswordPage(final PageParameters parameters) {
    super(parameters);

    add(new Header("header"));

    enclosingDiv = new WebMarkupContainer("enclosing-div");
    enclosingDiv.setOutputMarkupId(true);

    if (!session.isLoggedIn()) {
        error("not logged in");
        throw new RestartResponseAtInterceptPageException(LoginPage.class);
    }/*from w w w.  j  av  a2  s.co  m*/

    Form form = new Form("form");
    form.setOutputMarkupId(true);

    feedback = new FeedbackPanel("feedback");
    feedback.setOutputMarkupId(true);
    form.add(feedback);

    currentPasswordField = new PasswordTextField("current-password", new Model<String>());
    currentPasswordField.setRequired(true);

    passwordField = new PasswordTextField("password", new Model<String>());
    passwordField.setRequired(true);
    passwordField.add(StringValidator.lengthBetween(6, 32));

    PasswordTextField confirmPasswordField = new PasswordTextField("confirm-password", new Model<String>());
    confirmPasswordField.setRequired(true);

    form.add(currentPasswordField);
    form.add(passwordField);
    form.add(confirmPasswordField);

    form.add(new EqualPasswordInputValidator(passwordField, confirmPasswordField));

    AjaxButton submit = new AjaxButton("submit") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            String currentPassword = currentPasswordField.getModelObject();
            String newPassword = passwordField.getModelObject();
            User user = dao.findUserByEmail(session.getUsername());

            if (user == null) {
                error("not logged in");
                throw new RestartResponseAtInterceptPageException(LoginPage.class);
            } else if (currentPasswordIsValid(user, currentPassword)) {

                changePassword(user, newPassword);
                EntityManager em = emModel.getObject();
                em.persist(user);
                action.apply(em); // save changes
                successMessage.setVisible(true);
                form.setVisible(false);
            } else {
                error("current password is invalid");
            }

            target.add(enclosingDiv);
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(feedback);
            target.add(enclosingDiv);
        }
    };

    form.add(submit);
    enclosingDiv.add(form);

    successMessage = new WebMarkupContainer("success-message");
    successMessage.setOutputMarkupId(true);
    successMessage.setVisible(false);
    enclosingDiv.add(successMessage);

    add(enclosingDiv);

}

From source file:com.example.justaddwater.web.app.RecoverPasswordPage.java

License:Apache License

public RecoverPasswordPage(final PageParameters parameters) {
    super(parameters);
    add(new Header("header"));

    String token = parameters.get("token").toString();
    OneTimeLogin otl = dao.findOneTimeLoginByToken(token);
    if (otl == null) {
        error("login token invalid");
        throw new RestartResponseAtInterceptPageException(ForgotPasswordPage.class);
    } else if (otl.isExpired()) {
        error("login token expired");
        throw new RestartResponseAtInterceptPageException(ForgotPasswordPage.class);
    } else {/*from  w  w  w . ja  va2 s . c  o  m*/
        loginViaOneTimePassword(otl);
    }

    enclosure = new WebMarkupContainer("enclosure");
    enclosure.setOutputMarkupId(true);

    Form form = new Form("form") {
        @Override
        protected void onSubmit() {
            User user = session.getLoggedInUser();
            changePassword(user, passwordField.getModelObject());
            enclosure.setVisible(false);
            successMessage.setVisible(true);
        }
    };

    FeedbackPanel feedback = new FeedbackPanel("feedback");
    feedback.setOutputMarkupId(true);
    form.add(feedback);

    passwordField = new PasswordTextField("password", new Model<String>());
    passwordField.setRequired(true);
    passwordField.add(StringValidator.lengthBetween(6, 32));

    PasswordTextField confirmPasswordField = new PasswordTextField("confirmPassword", new Model<String>());
    confirmPasswordField.setRequired(true);

    form.add(passwordField);
    form.add(confirmPasswordField);
    form.add(new EqualPasswordInputValidator(passwordField, confirmPasswordField));

    successMessage = new WebMarkupContainer("successMessage");
    successMessage.setOutputMarkupId(true);
    successMessage.setVisible(false);
    add(successMessage);

    enclosure.add(form);
    add(enclosure);
}

From source file:com.example.justaddwater.web.app.SignupPage.java

License:Apache License

public SignupPage(final PageParameters parameters) {
    super(parameters);
    add(new Header("header"));

    Form form = new Form("form");
    form.setOutputMarkupId(true);/*from www . j a  v  a 2 s.co m*/

    feedback = new FeedbackPanel("feedback");
    feedback.setOutputMarkupId(true);
    form.add(feedback);

    form.add(new ExternalLink("fbLink", FacebookOAuthPage.getFacebookLoginUrl()));

    usernameField = new RequiredTextField<String>("username", new Model<String>());
    passwordField = new PasswordTextField("password", new Model<String>());
    passwordField.setRequired(true);
    passwordField.add(StringValidator.lengthBetween(6, 32));

    confirmPasswordField = new PasswordTextField("password-confirm", new Model<String>());
    confirmPasswordField.setRequired(true);

    form.add(usernameField);
    form.add(passwordField);
    form.add(confirmPasswordField);

    form.add(new EqualPasswordInputValidator(passwordField, confirmPasswordField));

    AjaxButton submit = new AjaxButton("submit") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            String username = usernameField.getModelObject();
            String pw = passwordField.getModelObject();

            User existingUser = dao.findUserByEmail(username);
            if (existingUser != null) {
                usernameField.error("a user with that username already exists, account type: "
                        + existingUser.getAuthenticationType());
                target.add(form);
            } else {
                User user = new User();
                createAccount(user, username, pw);
                setResponsePage(new AccountPage());
            }
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(feedback);
            target.add(form);
        }

    };
    form.add(submit);

    add(form);
}