aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/data
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/com/vaadin/data')
-rw-r--r--server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java54
-rw-r--r--server/src/com/vaadin/data/fieldgroup/FieldGroup.java6
-rw-r--r--server/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java2
-rw-r--r--server/src/com/vaadin/data/util/ListSet.java2
-rw-r--r--server/src/com/vaadin/data/util/MethodProperty.java30
-rw-r--r--server/src/com/vaadin/data/util/MethodPropertyDescriptor.java2
-rw-r--r--server/src/com/vaadin/data/util/converter/DefaultConverterFactory.java5
-rw-r--r--server/src/com/vaadin/data/util/converter/StringToBigDecimalConverter.java60
-rw-r--r--server/src/com/vaadin/data/util/converter/StringToNumberConverter.java65
-rw-r--r--server/src/com/vaadin/data/util/filter/Compare.java2
-rw-r--r--server/src/com/vaadin/data/util/filter/Like.java4
-rw-r--r--server/src/com/vaadin/data/validator/BeanValidator.java19
12 files changed, 149 insertions, 102 deletions
diff --git a/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java b/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java
index ff4ecc8426..e5d53b759d 100644
--- a/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java
+++ b/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java
@@ -225,4 +225,58 @@ public class BeanFieldGroup<T> extends FieldGroup {
}
return beanValidationImplementationAvailable;
}
+
+ /**
+ * Convenience method to bind Fields from a given "field container" to a
+ * given bean with buffering disabled.
+ * <p>
+ * The returned {@link BeanFieldGroup} can be used for further
+ * configuration.
+ *
+ * @see #bindFieldsBuffered(Object, Object)
+ * @see #bindMemberFields(Object)
+ * @since 7.2
+ * @param bean
+ * the bean to be bound
+ * @param objectWithMemberFields
+ * the class that contains {@link Field}s for bean properties
+ * @return the bean field group used to make binding
+ */
+ public static <T> BeanFieldGroup<T> bindFieldsUnbuffered(T bean,
+ Object objectWithMemberFields) {
+ return createAndBindFields(bean, objectWithMemberFields, false);
+ }
+
+ /**
+ * Convenience method to bind Fields from a given "field container" to a
+ * given bean with buffering enabled.
+ * <p>
+ * The returned {@link BeanFieldGroup} can be used for further
+ * configuration.
+ *
+ * @see #bindFieldsUnbuffered(Object, Object)
+ * @see #bindMemberFields(Object)
+ * @since 7.2
+ * @param bean
+ * the bean to be bound
+ * @param objectWithMemberFields
+ * the class that contains {@link Field}s for bean properties
+ * @return the bean field group used to make binding
+ */
+ public static <T> BeanFieldGroup<T> bindFieldsBuffered(T bean,
+ Object objectWithMemberFields) {
+ return createAndBindFields(bean, objectWithMemberFields, true);
+ }
+
+ private static <T> BeanFieldGroup<T> createAndBindFields(T bean,
+ Object objectWithMemberFields, boolean buffered) {
+ @SuppressWarnings("unchecked")
+ BeanFieldGroup<T> beanFieldGroup = new BeanFieldGroup<T>(
+ (Class<T>) bean.getClass());
+ beanFieldGroup.setItemDataSource(bean);
+ beanFieldGroup.setBuffered(buffered);
+ beanFieldGroup.bindMemberFields(objectWithMemberFields);
+ return beanFieldGroup;
+ }
+
}
diff --git a/server/src/com/vaadin/data/fieldgroup/FieldGroup.java b/server/src/com/vaadin/data/fieldgroup/FieldGroup.java
index 4772dce5e6..e647bdbf6d 100644
--- a/server/src/com/vaadin/data/fieldgroup/FieldGroup.java
+++ b/server/src/com/vaadin/data/fieldgroup/FieldGroup.java
@@ -23,7 +23,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
-import java.util.logging.Logger;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
@@ -55,9 +54,6 @@ import com.vaadin.util.ReflectTools;
*/
public class FieldGroup implements Serializable {
- private static final Logger logger = Logger.getLogger(FieldGroup.class
- .getName());
-
private Item itemDataSource;
private boolean buffered = true;
@@ -1019,9 +1015,7 @@ public class FieldGroup implements Serializable {
*/
public Field<?> buildAndBind(String caption, Object propertyId)
throws BindException {
- Class<?> type = getPropertyType(propertyId);
return buildAndBind(caption, propertyId, Field.class);
-
}
/**
diff --git a/server/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java b/server/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java
index 038b036f4e..eafd3573bc 100644
--- a/server/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java
+++ b/server/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java
@@ -95,7 +95,7 @@ public class ContainerHierarchicalWrapper implements Container.Hierarchical,
}
return 0;
}
- };
+ }
/**
* Constructs a new hierarchical wrapper for an existing Container. Works
diff --git a/server/src/com/vaadin/data/util/ListSet.java b/server/src/com/vaadin/data/util/ListSet.java
index c4201692d4..ccc9e0dbfd 100644
--- a/server/src/com/vaadin/data/util/ListSet.java
+++ b/server/src/com/vaadin/data/util/ListSet.java
@@ -82,7 +82,7 @@ public class ListSet<E> extends ArrayList<E> {
} else {
return false;
}
- };
+ }
/**
* Works as java.util.ArrayList#add(int, java.lang.Object) but returns
diff --git a/server/src/com/vaadin/data/util/MethodProperty.java b/server/src/com/vaadin/data/util/MethodProperty.java
index 5b9f3c90fd..5ec8ebffe0 100644
--- a/server/src/com/vaadin/data/util/MethodProperty.java
+++ b/server/src/com/vaadin/data/util/MethodProperty.java
@@ -19,6 +19,7 @@ package com.vaadin.data.util;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -85,6 +86,10 @@ public class MethodProperty<T> extends AbstractProperty<T> {
*/
private transient Class<? extends T> type;
+ private static final Object[] DEFAULT_GET_ARGS = new Object[0];
+
+ private static final Object[] DEFAULT_SET_ARGS = new Object[1];
+
/* Special serialization to handle method references */
private void writeObject(java.io.ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
@@ -108,7 +113,7 @@ public class MethodProperty<T> extends AbstractProperty<T> {
out.writeObject(null);
out.writeObject(null);
}
- };
+ }
/* Special serialization to handle method references */
private void readObject(java.io.ObjectInputStream in) throws IOException,
@@ -120,8 +125,9 @@ public class MethodProperty<T> extends AbstractProperty<T> {
Class<T> class1 = (Class<T>) SerializerHelper.readClass(in);
type = class1;
instance = in.readObject();
- setArgs = (Object[]) in.readObject();
- getArgs = (Object[]) in.readObject();
+ Object[] setArgs = (Object[]) in.readObject();
+ Object[] getArgs = (Object[]) in.readObject();
+ setArguments(getArgs, setArgs, setArgumentIndex);
String name = (String) in.readObject();
Class<?>[] paramTypes = SerializerHelper.readClassArray(in);
if (name != null) {
@@ -142,7 +148,7 @@ public class MethodProperty<T> extends AbstractProperty<T> {
} catch (NoSuchMethodException e) {
getLogger().log(Level.SEVERE, "Internal deserialization error", e);
}
- };
+ }
/**
* <p>
@@ -219,7 +225,7 @@ public class MethodProperty<T> extends AbstractProperty<T> {
type = (Class<T>) returnType;
}
- setArguments(new Object[] {}, new Object[] { null }, 0);
+ setArguments(DEFAULT_GET_ARGS, DEFAULT_SET_ARGS, 0);
this.instance = instance;
}
@@ -627,13 +633,15 @@ public class MethodProperty<T> extends AbstractProperty<T> {
*/
public void setArguments(Object[] getArgs, Object[] setArgs,
int setArgumentIndex) {
- this.getArgs = new Object[getArgs.length];
- for (int i = 0; i < getArgs.length; i++) {
- this.getArgs[i] = getArgs[i];
+ if (getArgs.length == 0) {
+ this.getArgs = DEFAULT_GET_ARGS;
+ } else {
+ this.getArgs = Arrays.copyOf(getArgs, getArgs.length);
}
- this.setArgs = new Object[setArgs.length];
- for (int i = 0; i < setArgs.length; i++) {
- this.setArgs[i] = setArgs[i];
+ if (Arrays.equals(setArgs, DEFAULT_SET_ARGS)) {
+ this.setArgs = DEFAULT_SET_ARGS;
+ } else {
+ this.setArgs = Arrays.copyOf(setArgs, setArgs.length);
}
this.setArgumentIndex = setArgumentIndex;
}
diff --git a/server/src/com/vaadin/data/util/MethodPropertyDescriptor.java b/server/src/com/vaadin/data/util/MethodPropertyDescriptor.java
index c0cdffe2e7..04a6ab1cc9 100644
--- a/server/src/com/vaadin/data/util/MethodPropertyDescriptor.java
+++ b/server/src/com/vaadin/data/util/MethodPropertyDescriptor.java
@@ -122,7 +122,7 @@ public class MethodPropertyDescriptor<BT> implements
} catch (NoSuchMethodException e) {
getLogger().log(Level.SEVERE, "Internal deserialization error", e);
}
- };
+ }
@Override
public String getName() {
diff --git a/server/src/com/vaadin/data/util/converter/DefaultConverterFactory.java b/server/src/com/vaadin/data/util/converter/DefaultConverterFactory.java
index b97a5b9047..fdf858a528 100644
--- a/server/src/com/vaadin/data/util/converter/DefaultConverterFactory.java
+++ b/server/src/com/vaadin/data/util/converter/DefaultConverterFactory.java
@@ -16,6 +16,7 @@
package com.vaadin.data.util.converter;
+import java.math.BigDecimal;
import java.util.Date;
import java.util.logging.Logger;
@@ -103,10 +104,10 @@ public class DefaultConverterFactory implements ConverterFactory {
return new StringToIntegerConverter();
} else if (Long.class.isAssignableFrom(sourceType)) {
return new StringToLongConverter();
+ } else if (BigDecimal.class.isAssignableFrom(sourceType)) {
+ return new StringToBigDecimalConverter();
} else if (Boolean.class.isAssignableFrom(sourceType)) {
return new StringToBooleanConverter();
- } else if (Number.class.isAssignableFrom(sourceType)) {
- return new StringToNumberConverter();
} else if (Date.class.isAssignableFrom(sourceType)) {
return new StringToDateConverter();
} else {
diff --git a/server/src/com/vaadin/data/util/converter/StringToBigDecimalConverter.java b/server/src/com/vaadin/data/util/converter/StringToBigDecimalConverter.java
new file mode 100644
index 0000000000..75d4cedd23
--- /dev/null
+++ b/server/src/com/vaadin/data/util/converter/StringToBigDecimalConverter.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.data.util.converter;
+
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.Locale;
+
+/**
+ * A converter that converts from {@link String} to {@link BigDecimal} and back.
+ * Uses the given locale and a {@link NumberFormat} instance for formatting and
+ * parsing.
+ * <p>
+ * Leading and trailing white spaces are ignored when converting from a String.
+ * </p>
+ * <p>
+ * Override and overwrite {@link #getFormat(Locale)} to use a different format.
+ * </p>
+ *
+ * @author Vaadin Ltd
+ * @since 7.2
+ */
+public class StringToBigDecimalConverter extends
+ AbstractStringToNumberConverter<BigDecimal> {
+ @Override
+ protected NumberFormat getFormat(Locale locale) {
+ NumberFormat numberFormat = super.getFormat(locale);
+ if (numberFormat instanceof DecimalFormat) {
+ ((DecimalFormat) numberFormat).setParseBigDecimal(true);
+ }
+
+ return numberFormat;
+ }
+
+ @Override
+ public BigDecimal convertToModel(String value,
+ Class<? extends BigDecimal> targetType, Locale locale)
+ throws com.vaadin.data.util.converter.Converter.ConversionException {
+ return (BigDecimal) convertToNumber(value, BigDecimal.class, locale);
+ }
+
+ @Override
+ public Class<BigDecimal> getModelType() {
+ return BigDecimal.class;
+ }
+}
diff --git a/server/src/com/vaadin/data/util/converter/StringToNumberConverter.java b/server/src/com/vaadin/data/util/converter/StringToNumberConverter.java
deleted file mode 100644
index 6d33000160..0000000000
--- a/server/src/com/vaadin/data/util/converter/StringToNumberConverter.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.data.util.converter;
-
-import java.text.NumberFormat;
-import java.util.Locale;
-
-/**
- * A converter that converts from {@link Number} to {@link String} and back.
- * Uses the given locale and {@link NumberFormat} for formatting and parsing.
- * <p>
- * Override and overwrite {@link #getFormat(Locale)} to use a different format.
- * </p>
- *
- * @author Vaadin Ltd
- * @since 7.0
- */
-public class StringToNumberConverter extends
- AbstractStringToNumberConverter<Number> {
-
- /*
- * (non-Javadoc)
- *
- * @see
- * com.vaadin.data.util.converter.Converter#convertToModel(java.lang.Object,
- * java.lang.Class, java.util.Locale)
- */
- @Override
- public Number convertToModel(String value,
- Class<? extends Number> targetType, Locale locale)
- throws ConversionException {
- if (targetType != getModelType()) {
- throw new ConversionException("Converter only supports "
- + getModelType().getName() + " (targetType was "
- + targetType.getName() + ")");
- }
-
- return convertToNumber(value, targetType, locale);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.data.util.converter.Converter#getModelType()
- */
- @Override
- public Class<Number> getModelType() {
- return Number.class;
- }
-
-}
diff --git a/server/src/com/vaadin/data/util/filter/Compare.java b/server/src/com/vaadin/data/util/filter/Compare.java
index 5a82392f77..1fcbe85580 100644
--- a/server/src/com/vaadin/data/util/filter/Compare.java
+++ b/server/src/com/vaadin/data/util/filter/Compare.java
@@ -37,7 +37,7 @@ public abstract class Compare implements Filter {
public enum Operation {
EQUAL, GREATER, LESS, GREATER_OR_EQUAL, LESS_OR_EQUAL
- };
+ }
private final Object propertyId;
private final Operation operation;
diff --git a/server/src/com/vaadin/data/util/filter/Like.java b/server/src/com/vaadin/data/util/filter/Like.java
index 656d3d5c32..9b7b2af292 100644
--- a/server/src/com/vaadin/data/util/filter/Like.java
+++ b/server/src/com/vaadin/data/util/filter/Like.java
@@ -23,11 +23,11 @@ public class Like implements Filter {
private final String value;
private boolean caseSensitive;
- public Like(String propertyId, String value) {
+ public Like(Object propertyId, String value) {
this(propertyId, value, true);
}
- public Like(String propertyId, String value, boolean caseSensitive) {
+ public Like(Object propertyId, String value, boolean caseSensitive) {
this.propertyId = propertyId;
this.value = value;
setCaseSensitive(caseSensitive);
diff --git a/server/src/com/vaadin/data/validator/BeanValidator.java b/server/src/com/vaadin/data/validator/BeanValidator.java
index b8c4e1b493..b25f7e687c 100644
--- a/server/src/com/vaadin/data/validator/BeanValidator.java
+++ b/server/src/com/vaadin/data/validator/BeanValidator.java
@@ -17,8 +17,6 @@
package com.vaadin.data.validator;
import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Locale;
import java.util.Set;
@@ -115,7 +113,9 @@ public class BeanValidator implements Validator {
Set<?> violations = getJavaxBeanValidator().validateValue(beanClass,
propertyName, value);
if (violations.size() > 0) {
- List<String> exceptions = new ArrayList<String>();
+ InvalidValueException[] causes = new InvalidValueException[violations
+ .size()];
+ int i = 0;
for (Object v : violations) {
final ConstraintViolation<?> violation = (ConstraintViolation<?>) v;
String msg = getJavaxBeanValidatorFactory()
@@ -123,16 +123,11 @@ public class BeanValidator implements Validator {
violation.getMessageTemplate(),
new SimpleContext(value, violation
.getConstraintDescriptor()), locale);
- exceptions.add(msg);
+ causes[i] = new InvalidValueException(msg);
+ ++i;
}
- StringBuilder b = new StringBuilder();
- for (int i = 0; i < exceptions.size(); i++) {
- if (i != 0) {
- b.append("<br/>");
- }
- b.append(exceptions.get(i));
- }
- throw new InvalidValueException(b.toString());
+
+ throw new InvalidValueException(null, causes);
}
}