Search in sources :

Example 1 with FormatterException

use of io.vertigo.dynamo.domain.metamodel.FormatterException in project vertigo by KleeGroup.

the class VegaUiObject method formatValue.

private String formatValue(final DtField dtField, final String value) {
    isChecked = false;
    getDtObjectErrors().clearErrors(dtField.getName());
    try {
        final Serializable typedValue = (Serializable) dtField.getDomain().stringToValue(value);
        doSetTypedValue(dtField, typedValue);
        return dtField.getDomain().valueToString(typedValue);
    } catch (final FormatterException e) {
        // We don't log nor rethrow this exception
        /**
         * Erreur de typage.
         */
        getDtObjectErrors().addError(StringUtil.constToLowerCamelCase(dtField.getName()), e.getMessageText());
        return value;
    }
}
Also used : FormatterException(io.vertigo.dynamo.domain.metamodel.FormatterException) Serializable(java.io.Serializable)

Example 2 with FormatterException

use of io.vertigo.dynamo.domain.metamodel.FormatterException in project vertigo by KleeGroup.

the class FormatterNumber method stringToValue.

/**
 * {@inheritDoc}
 */
@Override
public final Object stringToValue(final String strValue, final DataType dataType) throws FormatterException {
    checkType(dataType);
    // -----
    // Pour les nombres on "trim" à droite et à gauche
    String sValue = StringUtil.isEmpty(strValue) ? null : strValue.trim();
    if (sValue == null) {
        return null;
    }
    try {
        final DecimalFormatSymbols decimalFormatSymbols = getDecimalFormatSymbols();
        /**
         * Puis on transforme la chaine pour revenir à l'ecriture la plus simple.
         * Cela pour utiliser le Number.valueOf plutot que le parse de NumberFormat.
         */
        sValue = cleanStringNumber(sValue, decimalFormatSymbols);
        if (dataType == DataType.BigDecimal) {
            return new BigDecimal(sValue);
        } else if (dataType == DataType.Double) {
            return Double.valueOf(sValue);
        } else if (dataType == DataType.Integer) {
            return toInteger(sValue);
        } else if (dataType == DataType.Long) {
            return Long.valueOf(sValue);
        }
        throw new IllegalArgumentException("Type unsupported : " + dataType);
    } catch (final NumberFormatException e) {
        // cas des erreurs sur les formats de nombre
        throw new FormatterException(Resources.DYNAMOX_NUMBER_NOT_FORMATTED, e);
    }
}
Also used : FormatterException(io.vertigo.dynamo.domain.metamodel.FormatterException) DecimalFormatSymbols(java.text.DecimalFormatSymbols) BigDecimal(java.math.BigDecimal)

Aggregations

FormatterException (io.vertigo.dynamo.domain.metamodel.FormatterException)2 Serializable (java.io.Serializable)1 BigDecimal (java.math.BigDecimal)1 DecimalFormatSymbols (java.text.DecimalFormatSymbols)1