Example #1
0
    /** Return the indexes available for this field (for repeated fields ad List) */
    @SuppressWarnings("rawtypes")
    public List<Integer> indexes() {
      if (form.value().isPresent()) {
        BeanWrapper beanWrapper = new BeanWrapperImpl(form.value().get());
        beanWrapper.setAutoGrowNestedPaths(true);
        String objectKey = name;
        if (form.name() != null && name.startsWith(form.name() + ".")) {
          objectKey = name.substring(form.name().length() + 1);
        }

        List<Integer> result = new ArrayList<>();
        if (beanWrapper.isReadableProperty(objectKey)) {
          Object value = beanWrapper.getPropertyValue(objectKey);
          if (value instanceof Collection) {
            for (int i = 0; i < ((Collection) value).size(); i++) {
              result.add(i);
            }
          }
        }

        return result;

      } else {
        Set<Integer> result = new HashSet<>();
        Pattern pattern = Pattern.compile("^" + Pattern.quote(name) + "\\[(\\d+)\\].*$");

        for (String key : form.data().keySet()) {
          java.util.regex.Matcher matcher = pattern.matcher(key);
          if (matcher.matches()) {
            result.add(Integer.parseInt(matcher.group(1)));
          }
        }

        List<Integer> sortedResult = new ArrayList<>(result);
        Collections.sort(sortedResult);
        return sortedResult;
      }
    }
Example #2
0
 protected Object[] getArgumentsForConstraint(
     String objectName, String field, ConstraintDescriptor<?> descriptor) {
   List<Object> arguments = new LinkedList<>();
   String[] codes = new String[] {objectName + Errors.NESTED_PATH_SEPARATOR + field, field};
   arguments.add(new DefaultMessageSourceResolvable(codes, field));
   // Using a TreeMap for alphabetical ordering of attribute names
   Map<String, Object> attributesToExpose = new TreeMap<>();
   for (Map.Entry<String, Object> entry : descriptor.getAttributes().entrySet()) {
     String attributeName = entry.getKey();
     Object attributeValue = entry.getValue();
     if (!internalAnnotationAttributes.contains(attributeName)) {
       attributesToExpose.put(attributeName, attributeValue);
     }
   }
   arguments.addAll(attributesToExpose.values());
   return arguments.toArray(new Object[arguments.size()]);
 }
Example #3
0
 static {
   internalAnnotationAttributes.add("message");
   internalAnnotationAttributes.add("groups");
   internalAnnotationAttributes.add("payload");
 }