Search code examples
javagwt

GWT using iban4j on client side for validation


I need to validate the user input from 2 TextBoxes first on client Side and later on server side. I createt a class called FieldVerifier in the shared package. I have 2 Methods to validate IBAN and BIC with iban4j:

public static boolean isValidIban(String iban) {
    try {
        IbanUtil.validate(iban, IbanFormat.Default);
    } catch (Exception exc) {

        return false;
    } 
    return true;
}

public static boolean isValidBic(String bic) {
    try {
        BicUtil.validate(bic);
    } catch (Exception exc) {
        return false;
    }
    return true;
}

But if I try to start the application I get following error:

Line 91: No source code is available for type org.iban4j.IbanUtil; did you forget to inherit a required module?

Line 101: No source code is available for type org.iban4j.BicUtil; did you forget to inherit a required module?

Line 91: No source code is available for type org.iban4j.IbanFormat; did you forget to inherit a required module?

What do I need to do to build this library to use it on client side?


Solution

  • You set the the Validator class inside shared directory. So, the code for the Validator itself can be used in client side, but the dependencies (iban4j) need to be compatible with GWT also to be included on client side.

    To do what you want, you have 2 choices.

    • Add the code of iban4j directly in your shared directory - It means loose the link to the iban4j library
    • Transform the iban4j to a GWT module. ( this is done by adding in the iban4j jar the source code and a Iban4j.gwt.xml file) and include the module to your project - It means modify the current library or recompile it with your need