Ejemplo n.º 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;
      }
    }
Ejemplo n.º 2
0
 static {
   internalAnnotationAttributes.add("message");
   internalAnnotationAttributes.add("groups");
   internalAnnotationAttributes.add("payload");
 }