Example usage for org.apache.commons.validator.routines.checkdigit CheckDigitException getMessage

List of usage examples for org.apache.commons.validator.routines.checkdigit CheckDigitException getMessage

Introduction

In this page you can find the example usage for org.apache.commons.validator.routines.checkdigit CheckDigitException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:mobi.nordpos.catalog.action.ProductCreateActionBean.java

@ValidationMethod(priority = 1)
public void validateProductBarcode(ValidationErrors errors) {

    String prefix = getBarcodePrefix();

    if (!prefix.matches("\\d\\d\\d")) {
        prefix = DEFAULT_BARCODE_PREFIX;
    }//  w ww . j a va 2s.c om

    try {
        String plu = getPLU(getProduct().getProductCategory().getCode());
        String code = getShortCode();
        String barcode = prefix.concat(plu).concat(code);
        getProduct().setCode(barcode.concat(new EAN13CheckDigit().calculate(barcode)));
    } catch (CheckDigitException ex) {
        getContext().getValidationErrors().addGlobalError(new SimpleError(ex.getMessage()));
    } catch (SQLException ex) {
        getContext().getValidationErrors().addGlobalError(new SimpleError(ex.getMessage()));
    }
}