From e2532cb6257d111aa2ec722cf8d74dfb4ae1baf9 Mon Sep 17 00:00:00 2001 From: Zsombor Gegesy Date: Wed, 21 Jan 2015 14:52:11 +0100 Subject: [PATCH] Fix pattern decorator, because the UI expects 'value' instead of 'regexp' --- .../java/com/github/valdr/ConstraintAttributes.java | 8 ++++++++ .../com/github/valdr/decorator/PatternDecorator.java | 12 ++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/valdr-bean-validation/src/main/java/com/github/valdr/ConstraintAttributes.java b/valdr-bean-validation/src/main/java/com/github/valdr/ConstraintAttributes.java index c315f08..d9dde84 100644 --- a/valdr-bean-validation/src/main/java/com/github/valdr/ConstraintAttributes.java +++ b/valdr-bean-validation/src/main/java/com/github/valdr/ConstraintAttributes.java @@ -40,6 +40,14 @@ public int size() { public Object put(String key, Object value) { return map.put(key, value); } + + public Object remove(String key) { + return map.remove(key); + } + + public Object get(String key) { + return map.get(key); + } private void removeUnusedAttributes(Map annotationAttributes) { Iterator it = annotationAttributes.keySet().iterator(); diff --git a/valdr-bean-validation/src/main/java/com/github/valdr/decorator/PatternDecorator.java b/valdr-bean-validation/src/main/java/com/github/valdr/decorator/PatternDecorator.java index 738f904..12d0c53 100644 --- a/valdr-bean-validation/src/main/java/com/github/valdr/decorator/PatternDecorator.java +++ b/valdr-bean-validation/src/main/java/com/github/valdr/decorator/PatternDecorator.java @@ -1,10 +1,11 @@ package com.github.valdr.decorator; -import com.github.valdr.ConstraintAttributes; - +import java.util.HashMap; import java.util.Map; import java.util.Set; +import com.github.valdr.ConstraintAttributes; + /** * Decorates the map of attributes of the {@link javax.validation.constraints.Pattern} constraint. */ @@ -31,12 +32,15 @@ public PatternDecorator(ConstraintAttributes decoratee) { @Override public Set> entrySet() { Set> entrySet = getDecoratee().entrySet(); + Map result = new HashMap<>(); for (Map.Entry entry : entrySet) { if ("regexp".equals(entry.getKey())) { - entry.setValue(javaToJavaScriptRegexpPattern(entry)); + result.put("value", javaToJavaScriptRegexpPattern(entry)); + } else { + result.put(entry.getKey(), entry.getValue()); } } - return entrySet; + return result.entrySet(); } private String javaToJavaScriptRegexpPattern(Map.Entry entry) {