KilledByCHeese
KilledByCHeese

Reputation: 872

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?

Upvotes: 1

Views: 661

Answers (2)

El Hoss
El Hoss

Reputation: 3832

Just checked iban4j.

as wargre already mentioned, you have to do some work. iban4j can not be used with GWT without major changes.

You have to:

  • add a module descriptor to the lib
  • do some code changes (f.e.: String.format is not supported in GWT)
  • and the *.gwt.xml & the Java sources to the lib.

In this state the lib can not be used with GWT. There has to be done some major changes.

Update: I have ported iban4j to GWT: https://github.com/mvp4g/iban4g

Update 2:

iban4g has moved: https://github.com/NaluKit/iban4g and updated. This new version will work with Java, GWT and J2CL!

Upvotes: 1

wargre
wargre

Reputation: 4753

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

Upvotes: 1

Related Questions