org.apache.wicket.validation.IValidatable Java Examples
The following examples show how to use
org.apache.wicket.validation.IValidatable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HibernateValidatorProperty.java From pm-wicket-utils with GNU Lesser General Public License v3.0 | 6 votes |
public void validate(IValidatable<Object> validatable) { Validator validator = HibernateValidatorProperty.validatorFactory.getValidator(); @SuppressWarnings("unchecked") Set<ConstraintViolation<Object>> violations = validator.validateValue((Class<Object>)beanModel.getObject().getClass(), propertyName, validatable.getValue()); if(!violations.isEmpty()){ for(ConstraintViolation<?> violation : violations){ ValidationError error = new ValidationError(violation.getMessage()); String key = violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName(); if(getValidatorPrefix()!=null) key = getValidatorPrefix()+"."+key; error.addKey(key); error.setVariables(new HashMap<String, Object>(violation.getConstraintDescriptor().getAttributes())); //remove garbage from the attributes error.getVariables().remove("payload"); error.getVariables().remove("message"); error.getVariables().remove("groups"); validatable.error(error); } } }
Example #2
Source File: RegistrationPage.java From AppStash with Apache License 2.0 | 6 votes |
private Component usernameField() { TextField<String> username = new TextField<>("username", new PropertyModel<>(userInfoModel, "username")); username.add(new IValidator<String>() { private static final long serialVersionUID = 5670647976176255775L; @Override public void validate(IValidatable<String> userNameValidatable) { UserInfo userInfo = userService.findByUsername(userNameValidatable.getValue()); if (userInfo != null) { error("The entered username is already in use."); } } }); username.setRequired(true); return username; }
Example #3
Source File: PhoneNumberValidator.java From sakai with Educational Community License v2.0 | 6 votes |
/** * @see AbstractValidator#onValidate(IValidatable) */ protected void onValidate(IValidatable validatable) { //setup list List<String> regexs = new ArrayList<String>(); regexs.add("\\+?([0-9]+|\\s+)+(\\w+)?+"); //matches 1,2,3,5 with 10 regexs.add("\\({1}[0-9]+\\){1}([0-9]+|\\s+)+(\\w+)?+"); //matches 4 with 10 regexs.add("([0-9]+(\\-|\\.)?)+(\\w+)?+"); //matches 6, 7 with 10 regexs.add("\\({1}[0-9]+\\){1}([0-9]+|\\s+|\\-?|\\.?)+(\\w+)?+"); //matches 8,9 with 10 //check each, if none, error for(String r: regexs) { Pattern p = Pattern.compile(r); if (p.matcher((String)validatable.getValue()).matches()) { return; } } //if we haven't matched, error. error(validatable); }
Example #4
Source File: ForgetPasswordDialog.java From openmeetings with Apache License 2.0 | 6 votes |
@Override protected void onValidate() { String n = name.getConvertedInput(); if (n != null) { IValidatable<String> val = new Validatable<>(n); Type type = rg.getConvertedInput(); if (type == Type.email) { emailValidator.validate(val); if (!val.isValid()) { error(getString("234")); } } if (type == Type.login && n.length() < getMinLoginLength()) { error(getString("104")); } } }
Example #5
Source File: StrongPasswordValidator.java From openmeetings with Apache License 2.0 | 6 votes |
@Override public void validate(IValidatable<String> pass) { if (badLength(pass.getValue())) { error(pass, "bad.password.short", Map.of("0", getMinPasswdLength())); } if (noLowerCase(pass.getValue())) { error(pass, "bad.password.lower"); } if (noUpperCase(pass.getValue())) { error(pass, "bad.password.upper"); } if (noDigit(pass.getValue())) { error(pass, "bad.password.digit"); } if (noSymbol(pass.getValue())) { error(pass, "bad.password.special"); } if (hasStopWords(pass.getValue())) { error(pass, "bad.password.stop"); } }
Example #6
Source File: StrongPasswordValidator.java From openmeetings with Apache License 2.0 | 6 votes |
private void error(IValidatable<String> pass, String key, Map<String, Object> params) { if (web) { ValidationError err = new ValidationError().addKey(key); if (params != null) { err.setVariables(params); } pass.error(err); } else { String msg = LabelDao.getString(key, 1L); if (params != null && !params.isEmpty() && !Strings.isEmpty(msg)) { for (Map.Entry<String, Object> e : params.entrySet()) { msg = msg.replace(String.format("${%s}", e.getKey()), "" + e.getValue()); } } log.warn(msg); pass.error(new ValidationError(msg)); } }
Example #7
Source File: ManageUsersPage.java From webanno with Apache License 2.0 | 6 votes |
private void validateRoles(IValidatable<Collection<Role>> aValidatable) { Collection<Role> newRoles = aValidatable.getValue(); if (newRoles.isEmpty()) { aValidatable.error(new ValidationError() .setMessage("A user has to have at least one role.")); } // enforce users to have at least the ROLE_USER role if (!newRoles.contains(Role.ROLE_USER)) { aValidatable.error(new ValidationError() .setMessage("Every user must have 'ROLE_USER'.")); } // don't let an admin user strip himself of admin rights if (userRepository.getCurrentUser().equals(getModelObject()) && !newRoles.contains(Role.ROLE_ADMIN)) { aValidatable.error(new ValidationError() .setMessage("You cannot remove your own admin status.")); } }
Example #8
Source File: RegistrationPage.java From the-app with Apache License 2.0 | 6 votes |
private Component usernameField() { TextField<String> username = new TextField<>("username", new PropertyModel<>(userInfoModel, "username")); username.add(new IValidator<String>() { private static final long serialVersionUID = 5670647976176255775L; @Override public void validate(IValidatable<String> userNameValidatable) { UserInfo userInfo = userService.findByUsername(userNameValidatable.getValue()); if (userInfo != null) { error("The entered username is already in use."); } } }); username.setRequired(true); return username; }
Example #9
Source File: URIValidator.java From ontopia with Apache License 2.0 | 6 votes |
@Override protected void onValidate(IValidatable<String> validatable) { final String value = validatable.getValue(); if (value == null) return; try { new URILocator(value); } catch (Exception e) { String message = Application.get().getResourceSettings().getLocalizer().getString(resourceKey(), (Component)null, new Model<Serializable>(new Serializable() { @SuppressWarnings("unused") public String getValue() { return value; } })); component.error(AbstractFieldInstancePanel.createErrorMessage(fieldInstanceModel, new Model<String>(message))); } }
Example #10
Source File: PhoneNumberValidator.java From sakai with Educational Community License v2.0 | 6 votes |
/** * @see AbstractValidator#onValidate(IValidatable) */ protected void onValidate(IValidatable validatable) { //setup list List<String> regexs = new ArrayList<String>(); regexs.add("\\+?([0-9]+|\\s+)+(\\w+)?+"); //matches 1,2,3,5 with 10 regexs.add("\\({1}[0-9]+\\){1}([0-9]+|\\s+)+(\\w+)?+"); //matches 4 with 10 regexs.add("([0-9]+(\\-|\\.)?)+(\\w+)?+"); //matches 6, 7 with 10 regexs.add("\\({1}[0-9]+\\){1}([0-9]+|\\s+|\\-?|\\.?)+(\\w+)?+"); //matches 8,9 with 10 //check each, if none, error for(String r: regexs) { Pattern p = Pattern.compile(r); if (p.matcher((String)validatable.getValue()).matches()) { return; } } //if we haven't matched, error. error(validatable); }
Example #11
Source File: IdentityValidator.java From ontopia with Apache License 2.0 | 6 votes |
@Override protected void onValidate(IValidatable<String> validatable) { String value = validatable.getValue(); if (value == null) return; LocatorIF locator; try { locator = new URILocator(value); } catch (Exception e) { reportError("validators.IdentityValidator.invalidURI", value); return; } Topic topic = fieldInstanceModel.getFieldInstance().getInstance(); TopicMap topicMap = topic.getTopicMap(); TopicMapIF topicMapIf = topicMap.getTopicMapIF(); TopicIF topicIf = topic.getTopicIF(); TopicIF otopic = topicMapIf.getTopicBySubjectIdentifier(locator); if (otopic != null && !Objects.equals(topicIf, otopic)) reportError("validators.IdentityValidator.subjectIdentifierClash", value); otopic = topicMapIf.getTopicBySubjectLocator(locator); if (otopic != null && !Objects.equals(topicIf, otopic)) reportError("validators.IdentityValidator.subjectLocatorClash", value); }
Example #12
Source File: DateFormatValidator.java From ontopia with Apache License 2.0 | 6 votes |
@Override protected void onValidate(IValidatable<String> validatable) { final String value = validatable.getValue(); if (value == null) return; try { DateFormat df = createDateFormat(); df.parse(value); } catch (ParseException e) { String message = Application.get().getResourceSettings().getLocalizer().getString(resourceKey(), (Component)null, new Model<Serializable>(new Serializable() { @SuppressWarnings("unused") public String getValue() { return value; } })); component.error(AbstractFieldInstancePanel.createErrorMessage(fieldInstanceModel, new Model<String>(message))); } }
Example #13
Source File: RecommenderEditorPanel.java From inception with Apache License 2.0 | 6 votes |
@Override public void validate(IValidatable<String> aValidatable) { String newName = aValidatable.getValue(); Recommender currentRecommender = recommender.getObject(); Optional<Recommender> recommenderWithNewName = recommendationService .getRecommender(project.getObject(), newName); // Either there should be no recommender with the new name already existing or it should // be the recommender we are currently editing (i.e. the name has not changed) if ( recommenderWithNewName.isPresent() && !Objects.equals(recommenderWithNewName.get().getId(), currentRecommender.getId()) ) { aValidatable.error(new ValidationError( "Another recommender with the same name exists. Please try a different name")); } }
Example #14
Source File: RegexValidator.java From ontopia with Apache License 2.0 | 6 votes |
@Override protected void onValidate(IValidatable<String> validatable) { final String value = validatable.getValue(); final String regex = getRegex(); if (value == null) return; try { if (value.matches(regex)) return; else reportError(resourceKeyInvalidValue(), value, regex); } catch (PatternSyntaxException e) { reportError(resourceKeyInvalidRegex(), value, regex); } }
Example #15
Source File: KontoFormComponent.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("serial") public KontoFormComponent(final String id, final IModel<KontoDO> model, final boolean required) { super(id, model); if (required == true) { setRequired(true); add(new AbstractValidator<KontoDO>() { @Override protected void onValidate(final IValidatable<KontoDO> validatable) { final KontoDO value = validatable.getValue(); if (value == null) { error(validatable); } } @Override public boolean validateOnNullValue() { return true; } @Override protected String resourceKey() { return "fibu.konto.error.invalidKonto"; } }); } this.withLabelValue(true).withMatchContains(true).withMinChars(2).withWidth(500); enableTooltips(); }
Example #16
Source File: PortugueseNIFValidator.java From pm-wicket-utils with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void validate(IValidatable<String> validatable) { super.validate(validatable); final String value = validatable.getValue(); if(value==null || value.length()==0) return; try { if(!isNIFValid(value)) validatable.error(new ValidationError(this)); } catch(NumberFormatException e){ validatable.error(new ValidationError(this)); } }
Example #17
Source File: DateFormatValidator.java From wicket-orientdb with Apache License 2.0 | 5 votes |
@Override public void validate(IValidatable<String> validatable) { String pattern = validatable.getValue(); try { newDateFormat(pattern).format(new Date()); } catch (Exception e) { ValidationError error = new ValidationError(this); error.setVariable("pattern", pattern); validatable.error(decorate(error, validatable)); } }
Example #18
Source File: OPropertyValueValidator.java From wicket-orientdb with Apache License 2.0 | 5 votes |
protected void validateLink(final IValidatable<T> validatable, final OProperty p, final Object linkValue) { if (linkValue == null) validatable.error(newValidationError("nulllink")); else { ORecord linkedRecord = null; if (linkValue instanceof OIdentifiable) linkedRecord = ((OIdentifiable) linkValue).getRecord(); else if (linkValue instanceof String) linkedRecord = new ORecordId((String) linkValue).getRecord(); else validatable.error(newValidationError("linkwrong")); if (linkedRecord != null && p.getLinkedClass() != null) { if (!(linkedRecord instanceof ODocument)) validatable.error(newValidationError("linktypewrong", "linkedClass", p.getLinkedClass(), "identity", linkedRecord.getIdentity())); final ODocument doc = (ODocument) linkedRecord; // AT THIS POINT CHECK THE CLASS ONLY IF != NULL BECAUSE IN CASE // OF GRAPHS THE RECORD COULD BE PARTIAL if (doc.getSchemaClass() != null && !p.getLinkedClass().isSuperClassOf( doc.getSchemaClass())) validatable.error(newValidationError("linktypewrong", "linkedClass", p.getLinkedClass(), "identity", linkedRecord.getIdentity())); } } }
Example #19
Source File: OPropertyValueValidator.java From wicket-orientdb with Apache License 2.0 | 5 votes |
protected void validateEmbedded(final IValidatable<T> validatable, final OProperty p, final Object fieldValue) { if (fieldValue instanceof ORecordId) { validatable.error(newValidationError("embeddedRecord")); return; } else if (fieldValue instanceof OIdentifiable) { if (((OIdentifiable) fieldValue).getIdentity().isValid()) { validatable.error(newValidationError("embeddedRecord")); return; } final OClass embeddedClass = p.getLinkedClass(); if (embeddedClass != null) { final ORecord rec = ((OIdentifiable) fieldValue).getRecord(); if (!(rec instanceof ODocument)) { validatable.error(newValidationError("embeddedNotDoc")); return; } final ODocument doc = (ODocument) rec; if (doc.getSchemaClass() == null || !(doc.getSchemaClass().isSubClassOf(embeddedClass))) { validatable.error(newValidationError("embeddedWrongType", "expectedType", embeddedClass.getName())); return; } } } else { validatable.error(newValidationError("embeddedNotDoc")); return; } }
Example #20
Source File: UserEmailValidator.java From Orienteer with Apache License 2.0 | 5 votes |
@Override public void validate(IValidatable<String> validatable) { String email = validatable.getValue(); if (OrienteerUserRepository.isUserExistsWithEmail(email)) { ValidationError error = new ValidationError(this); error.setVariable("email", email); validatable.error(error); } }
Example #21
Source File: GeneralSettingsPanel.java From inception with Apache License 2.0 | 5 votes |
@Override public void validate(IValidatable<String> aValidatable) { String kbName = aValidatable.getValue(); if (kbService.knowledgeBaseExists(projectModel.getObject(), kbName)) { String message = String.format( "There already exists a knowledge base in the project with name: [%s]!", kbName); aValidatable.error(new ValidationError(message)); } }
Example #22
Source File: Kost1FormComponent.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("serial") public Kost1FormComponent(final String id, final IModel<Kost1DO> model, final boolean required, final boolean tooltipRightAlignment) { super(id, model, tooltipRightAlignment); if (required == true) { setRequired(true); add(new AbstractValidator<Kost1DO>() { @Override protected void onValidate(final IValidatable<Kost1DO> validatable) { final Kost1DO value = validatable.getValue(); if (value == null) { error(validatable); } } @Override public boolean validateOnNullValue() { return true; } @Override protected String resourceKey() { return "fibu.kost.error.invalidKost"; } }); } this.withLabelValue(true).withMatchContains(true).withMinChars(2).withWidth(200); enableTooltips(); }
Example #23
Source File: Kost2DropDownChoice.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("serial") public Kost2DropDownChoice(final String componentId, final Kost2DO kost2, final Integer taskId) { super(componentId); setModel(new Model<Integer>() { public Integer getObject() { return getKost2Id(); } public void setObject(final Integer kost2Id) { setKost2Id(kost2Id); } }); this.kost2 = kost2; this.taskId = taskId; refreshChoiceRenderer(); setNullValid(true); add(new AbstractValidator<Integer>() { @Override protected void onValidate(IValidatable<Integer> validatable) { final Integer value = validatable.getValue(); if (value != null && value >= 0) { return; } if (CollectionUtils.isNotEmpty(kost2List) == true) { // Kost2 available but not selected. error(validatable); } } @Override protected String resourceKey() { return "timesheet.error.kost2Required"; } }); }
Example #24
Source File: Kost2FormComponent.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("serial") public Kost2FormComponent(final String id, final IModel<Kost2DO> model, final boolean required, final boolean tooltipRightAlignment) { super(id, model, tooltipRightAlignment); if (required == true) { setRequired(true); add(new AbstractValidator<Kost2DO>() { @Override protected void onValidate(final IValidatable<Kost2DO> validatable) { final Kost2DO value = validatable.getValue(); if (value == null) { error(validatable); } } @Override public boolean validateOnNullValue() { return true; } @Override protected String resourceKey() { return "fibu.kost.error.invalidKost"; } }); } this.withLabelValue(true).withMatchContains(true).withMinChars(2).withWidth(500); enableTooltips(); }
Example #25
Source File: TimesheetEditForm.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("serial") protected static DropDownChoice<Integer> createCost2ChoiceRenderer(final String id, final TimesheetDao timesheetDao, final TaskTree taskTree, final LabelValueChoiceRenderer<Integer> kost2ChoiceRenderer, final TimesheetDO data, final List<Kost2DO> kost2List) { final DropDownChoice<Integer> choice = new DropDownChoice<Integer>(id, new Model<Integer>() { @Override public Integer getObject() { return data.getKost2Id(); } @Override public void setObject(final Integer kost2Id) { if (kost2Id != null) { timesheetDao.setKost2(data, kost2Id); } else { data.setKost2(null); } } }, kost2ChoiceRenderer.getValues(), kost2ChoiceRenderer); choice.setNullValid(true); choice.add(new IValidator<Integer>() { @Override public void validate(final IValidatable<Integer> validatable) { final Integer value = validatable.getValue(); if (value != null && value >= 0) { return; } if (CollectionUtils.isNotEmpty(kost2List) == true) { // Kost2 available but not selected. choice.error(PFUserContext.getLocalizedString("timesheet.error.kost2Required")); } } }); return choice; }
Example #26
Source File: PhoneNumberValidator.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
@Override protected void onValidate(final IValidatable<String> validatable) { if (StringHelper.checkPhoneNumberFormat(validatable.getValue()) == false) { validatable.error(new ValidationError().addMessageKey("address.error.phone.invalidFormat")); } }
Example #27
Source File: IntervalFieldStringValidator.java From nextreports-server with Apache License 2.0 | 5 votes |
@Override public void validate(IValidatable<String> validatable) { boolean hasError = false; String s = validatable.getValue(); String[] elements = s.split(","); if (elements.length > 1) { List<String> nonDuplicatesList = new ArrayList<String>(new LinkedHashSet<String>(Arrays.asList(elements))); if (elements.length != nonDuplicatesList.size()) { // have duplicates hasError = true; } } else { elements = s.split("-"); if (elements.length == 2) { if (SelectIntervalPanel.getComparator(entityType, false).compare(elements[0], elements[1]) >= 0) { hasError = true; } } } if (hasError) { ValidationError error = new ValidationError(); String messageKey = Classes.simpleName(IntervalFieldStringValidator.class); error.addKey(messageKey); validatable.error(error); } }
Example #28
Source File: FoundEntityValidator.java From nextreports-server with Apache License 2.0 | 5 votes |
@Override public void validate(IValidatable<String> validatable) { String value = validatable.getValue(); String path = StorageUtil.createPath(parentPath, value); if (storageService.entityExists(path)) { ValidationError error = new ValidationError(); String message = String.format(errorMessage, value); error.setMessage(message); validatable.error(error); } }
Example #29
Source File: AnalysisNameValidator.java From nextreports-server with Apache License 2.0 | 5 votes |
@Override public void validate(IValidatable<String> validatable) { String value = validatable.getValue(); if (value.contains(" ")) { ValidationError error = new ValidationError(); String errorM = errorMessage; if (errorM == null) { errorM = "' ' not allowed in name"; } error.setMessage(errorM); validatable.error(error); } else { super.validate(validatable); } }
Example #30
Source File: ManageUsersPage.java From webanno with Apache License 2.0 | 5 votes |
private void validateEnabled(IValidatable<Boolean> aValidatable) { if (!aValidatable.getValue() && userRepository.getCurrentUser().equals(getModelObject())) { aValidatable.error(new ValidationError() .setMessage("You cannot disable your own account.")); } }