Search in sources :

Example 1 with ValidationException

use of com.webobjects.foundation.NSValidation.ValidationException in project wonder-slim by undur.

the class AjaxInPlaceEditor method handleRequest.

// Formatting/Parsing method "inspired by" WOTextField
@Override
public WOActionResults handleRequest(WORequest request, WOContext context) {
    WOComponent component = context.component();
    String strValue = request.stringFormValueForKey("value");
    Object objValue = strValue;
    if (strValue != null) {
        Format format = null;
        if (strValue.length() != 0) {
            format = WOFormatterRepository.formatterForComponent(component, _dateFormat, _numberFormat, _formatter);
        }
        if (format != null) {
            try {
                Object parsedValue = format.parseObject(strValue);
                String formattedValue = format.format(parsedValue);
                objValue = format.parseObject(formattedValue);
            } catch (ParseException parseexception) {
                String valueKeyPath = _valueAssociation.keyPath();
                ValidationException validationexception = new ValidationException(parseexception.getMessage(), strValue, valueKeyPath);
                component.validationFailedWithException(validationexception, strValue, valueKeyPath);
                return null;
            }
            if (objValue != null && _useDecimalNumber != null && _useDecimalNumber.booleanValueInComponent(component)) {
                objValue = new BigDecimal(objValue.toString());
            }
        } else if (objValue.toString().length() == 0) {
            objValue = null;
        }
    }
    _valueAssociation.setValue(objValue, component);
    // just executing action, ignoring result
    valueForBinding("action", component);
    WOResponse response = AjaxUtils.createResponse(request, context);
    _appendValueAttributeToResponse(response, context);
    return response;
}
Also used : Format(java.text.Format) ValidationException(com.webobjects.foundation.NSValidation.ValidationException) WOComponent(com.webobjects.appserver.WOComponent) ParseException(java.text.ParseException) WOResponse(com.webobjects.appserver.WOResponse) BigDecimal(java.math.BigDecimal)

Aggregations

WOComponent (com.webobjects.appserver.WOComponent)1 WOResponse (com.webobjects.appserver.WOResponse)1 ValidationException (com.webobjects.foundation.NSValidation.ValidationException)1 BigDecimal (java.math.BigDecimal)1 Format (java.text.Format)1 ParseException (java.text.ParseException)1