GWT 在客户端使用 iban4j 进行验证

GWT using iban4j on client side for validation

我需要首​​先在客户端验证来自 2 个文本框的用户输入,然后在服务器端验证。我在共享包中创建了一个名为 FieldVerifier 的 class。 我有两种使用 iban4j 验证 IBAN 和 BIC 的方法:

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;
}

但是如果我尝试启动应用程序,我会收到以下错误:

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?

我需要做什么来构建这个库以在客户端使用它?

您在共享目录中设置了Validator class。因此,Validator 本身的代码可以在客户端使用,但依赖项 (iban4j) 需要与 GWT 兼容,以便在客户端包含。

做你想做的事,你有2个选择。

  • 直接在您的共享目录中添加 iban4j 的代码 - 这意味着将 link 松散到 iban4j 库中
  • 将 iban4j 转换为 GWT 模块。 (这是通过在 iban4j jar 中添加源代码和 Iban4j.gwt.xml 文件来完成的)并将模块包含到您的项目中 - 这意味着修改当前库或根据需要重新编译它

刚刚查看了iban4j。

正如 wargre 已经提到的,你必须做一些工作。如果不进行重大更改,iban4j 不能与 GWT 一起使用。

你必须:

  • 向库添加模块描述符
  • 做一些代码更改(f.e.: GWT 不支持 String.format)
  • 和 *.gwt.xml & Java 资源库。

在此状态下,该库无法与 GWT 一起使用。必须进行一些重大更改。

更新:我已将 iban4j 移植到 GWT:https://github.com/mvp4g/iban4g

更新二:

iban4g 已移动:https://github.com/NaluKit/iban4g 并更新。 这个新版本将与 Java、GWT 和 J2CL 一起使用!