一个Wicket验证示例

阅读更多
Java文件:
add(new RequiredMaxLengthTextField("name", new PropertyModel(getData(), "name")).add(new AbstractValidator() {
      @Override
      protected void onValidate(IValidatable validatable)
      {
        final String groupname = validatable.getValue();
        if (groupname == null) {
          return;
        }
        getData().setName(groupname);
        if (groupDao.doesGroupnameAlreadyExist(getData()) == true) {
          error(validatable);
        }
      }

      @Override
      protected String resourceKey()
      {
        return "group.error.groupnameAlreadyExists";
      }
    }));


I18nResources.properties文件:
group.error.groupnameAlreadyExists=Group name already exists.

你可能感兴趣的:(wicket,验证)