Java Code Examples for org.apache.wicket.validation.IValidatable#getValue()

The following examples show how to use org.apache.wicket.validation.IValidatable#getValue() . 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: RecommenderEditorPanel.java    From inception with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: URIValidator.java    From ontopia with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: RegexValidator.java    From ontopia with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: DateFormatValidator.java    From ontopia with Apache License 2.0 6 votes vote down vote up
@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 5
Source File: IdentityValidator.java    From ontopia with Apache License 2.0 6 votes vote down vote up
@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 6
Source File: ManageUsersPage.java    From webanno with Apache License 2.0 6 votes vote down vote up
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 7
Source File: KeyBindingsConfigurationPanel.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Override
public void validate(IValidatable<String> aValidatable)
{
    String keyCombo = aValidatable.getValue();
    KeyBinding keyBinding = new KeyBinding(keyCombo, null);
    if (!keyBinding.isValid()) {
        aValidatable.error(new ValidationError("Invalid key combo: [" + keyCombo + "]"));
    }
}
 
Example 8
Source File: ProjectDetailPanel.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Override
public void validate(IValidatable<String> aValidatable)
{
    String newName = aValidatable.getValue();
    if (isNotBlank(newName) && !NameUtil.isNameValid(newName)) {
        aValidatable.error(new ValidationError(
                "Project name shouldn't contain characters such as /\\*?&!$+[^]"));
    }
}
 
Example 9
Source File: ProjectDetailPanel.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Override
public void validate(IValidatable<String> aValidatable)
{
    String newName = aValidatable.getValue();
    String oldName = aValidatable.getModel().getObject();
    if (!StringUtils.equals(newName, oldName) && isNotBlank(newName)
            && projectService.existsProject(newName)) {
        aValidatable.error(new ValidationError(
                "Another project with the same name exists. Please try a different name"));
    }
}
 
Example 10
Source File: AnalysisNameValidator.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: ToggleBox.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Override
public void validate(IValidatable<Boolean> aValidatable)
{
    if (aValidatable.getValue() == null) {
        aValidatable.error(new ValidationError("You need to make a choice."));
    }
}
 
Example 12
Source File: UsernameTextField.java    From wicket-spring-boot with Apache License 2.0 5 votes vote down vote up
@Override
public void validate(IValidatable<String> validatable) {
	final String field = validatable.getValue();
	if(service.usernameExists(field)){
		ValidationError error = new ValidationError();
		error.setMessage(getString(getClass().getSimpleName()));
		validatable.error(error);
	}
	
}
 
Example 13
Source File: TagEditorPanel.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Override
public void validate(IValidatable<String> aValidatable)
{
    String newName = aValidatable.getValue();
    String oldName = aValidatable.getModel().getObject();
    if (!StringUtils.equals(newName, oldName) && isNotBlank(newName)
            && annotationSchemaService.existsTag(newName, selectedTagSet.getObject())) {
        aValidatable.error(new ValidationError(
                "Another tag with the same name exists. Please try a different name"));
    }
}
 
Example 14
Source File: GeneralSettingsPanel.java    From inception with Apache License 2.0 5 votes vote down vote up
@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 15
Source File: PortugueseNIFValidator.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 16
Source File: FoundEntityValidator.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
@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 17
Source File: UserEmailValidator.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@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 18
Source File: IntervalFieldStringValidator.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
@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 19
Source File: CustomPatternValidator.java    From yes-cart with Apache License 2.0 4 votes vote down vote up
@Override
protected IValidationError decorate(final IValidationError error, final IValidatable<String> validatable) {
    final String value = validatable.getValue();
    return (IValidationError) messageSource -> errorLabelModel.getObject().replace("${input}", value);
}
 
Example 20
Source File: ZeroRangeValidator.java    From nextreports-server with Apache License 2.0 3 votes vote down vote up
@Override
public void validate(IValidatable<Integer> validatable) {

	final Integer number = validatable.getValue();

	if (!number.equals(0) && ((number < min) || (number > max)) ) {
		error(validatable, "ZeroRangeValidator");
	}

}